]> git.lyx.org Git - lyx.git/blobdiff - src/paragraph.C
mathed31.diff
[lyx.git] / src / paragraph.C
index 0360feceb7f6bf21bc1b6c5918e1f4e6d8ca9f56..ad157534de40f6fb81c50fa17bd21079bf52ecdd 100644 (file)
@@ -68,9 +68,7 @@ unsigned int LyXParagraph::paragraph_id = 0;
 
 LyXParagraph::LyXParagraph()
 {
-#ifndef HAVE_ROPE
        text.reserve(500); // is this number too big?
-#endif
        for (int i = 0; i < 10; ++i) setCounter(i , 0);
        appendix = false;
        enumdepth = 0;
@@ -93,9 +91,7 @@ LyXParagraph::LyXParagraph()
 // This konstruktor inserts the new paragraph in a list.
 LyXParagraph::LyXParagraph(LyXParagraph * par)
 {
-#ifndef HAVE_ROPE
        text.reserve(500);
-#endif
        par->fitToSize();
        
        for (int i = 0; i < 10; ++i) setCounter(i, 0);
@@ -560,11 +556,9 @@ void LyXParagraph::Erase(LyXParagraph::size_type pos)
                                insetlist.erase(it);
                        }
                }
-#ifndef HAVE_ROPE
+
                text.erase(text.begin() + pos);
-#else
-               text.erase(text.mutable_begin() + pos);
-#endif
+
                // Erase entries in the tables.
                FontTable search_font(pos, LyXFont());
                
@@ -640,11 +634,8 @@ void LyXParagraph::InsertChar(LyXParagraph::size_type pos,
 #else
        Assert(pos <= size());
 #endif
-#ifndef HAVE_ROPE
        text.insert(text.begin() + pos, c);
-#else
-       text.insert(pos, c);
-#endif
+
        // Update the font table.
        FontTable search_font(pos, LyXFont());
        for (FontList::iterator it = lower_bound(fontlist.begin(),
@@ -840,8 +831,7 @@ LyXFont const LyXParagraph::GetFontSettings(BufferParams const & bparams,
                                "position does not exist. "
                               << pos << " (" << static_cast<int>(pos)
                               << ")" << endl;
-       }
-       else if (pos > 0) {
+       } else if (pos > 0) {
                return GetFontSettings(bparams, pos - 1);
        }
 #else
@@ -855,6 +845,7 @@ LyXFont const LyXParagraph::GetFontSettings(BufferParams const & bparams,
        //return LyXFont(LyXFont::ALL_INHERIT);
 }
 
+
 // Gets uninstantiated font setting at position 0
 LyXFont const LyXParagraph::GetFirstFontSettings() const
 {
@@ -1018,6 +1009,47 @@ LyXParagraph::GetChar(LyXParagraph::size_type pos) const
 }
 
 
+LyXParagraph::value_type
+LyXParagraph::GetUChar(BufferParams const & bparams,
+                      LyXParagraph::size_type pos) const
+{
+       value_type c = GetChar(pos);
+       if (!lyxrc.rtl_support)
+               return c;
+
+       value_type uc = c;
+       switch (c) {
+       case '(':
+               uc = ')';
+               break;
+       case ')':
+               uc = '(';
+               break;
+       case '[':
+               uc = ']';
+               break;
+       case ']':
+               uc = '[';
+               break;
+       case '{':
+               uc = '}';
+               break;
+       case '}':
+               uc = '{';
+               break;
+       case '<':
+               uc = '>';
+               break;
+       case '>':
+               uc = '<';
+               break;
+       }
+       if (uc != c && GetFontSettings(bparams, pos).isRightToLeft())
+               return uc;
+       else
+               return c;
+}
+
 // return an string of the current word, and the end of the word in lastpos.
 string const LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const
 {
@@ -2205,6 +2237,9 @@ int LyXParagraph::GetPositionOfInset(Inset * inset) const
                        return (*cit).pos;
                }
        }
+       if (inset == bibkey)
+               return 0;
+
 #ifndef NEW_INSETS
        // Think about footnotes.
        if (footnoteflag == LyXParagraph::NO_FOOTNOTE 
@@ -2373,25 +2408,21 @@ LyXParagraph * LyXParagraph::TeXOnePar(Buffer const * buf,
        // This is necessary because LaTeX (and LyX on the screen)
        // calculates the space between the baselines according
        // to this font. (Matthias)
+       //
+       // Is this really needed ? (Dekel)
+       // We do not need to use to change the font for the last paragraph
+       // or for a command.
        LyXFont font = getFont(bparams, Last() - 1);
-       if (need_par && next) {
-               if (style.resfont.size() != font.size()) {
-                       os << '\\'
-                          << font.latexSize()
-                          << ' ';
-               }
+       bool is_command = textclasslist.Style(bparams.textclass,
+                                             GetLayout()).isCommand();
+       if (style.resfont.size() != font.size() && next && !is_command) {
+               if (!need_par)
+                       os << "{";
+               os << "\\" << font.latexSize() << " \\par}";
+       } else if (need_par) {
                os << "\\par}";
-       } else if (textclasslist.Style(bparams.textclass,
-                                      GetLayout()).isCommand()) {
-               if (style.resfont.size() != font.size()) {
-                       os << '\\'
-                          << font.latexSize()
-                          << ' ';
-               }
-               os << '}';
-       } else if ((style.resfont.size() != font.size()) && next){
-               os << "{\\" << font.latexSize() << " \\par}";
-       }
+       } else if (is_command)
+               os << "}";
 
        if (language->babel() != doc_language->babel() &&
            (!par
@@ -2422,7 +2453,11 @@ LyXParagraph * LyXParagraph::TeXOnePar(Buffer const * buf,
                        break;
        default:
                // we don't need it for the last paragraph!!!
+               // or for tables in floats
+               //   -- effectively creates a \par where there isn't one which
+               //      breaks a \subfigure or \subtable.
                if (next) {
+//                 && footnoteflag == LyXParagraph::NO_FOOTNOTE) {
                        os << '\n';
                        texrow.newline();
                }
@@ -2548,9 +2583,11 @@ bool LyXParagraph::SimpleTeXOnePar(Buffer const * buf,
                        if (style.isCommand()) {
                                os << '{';
                                ++column;
-                       } else if (align != LYX_ALIGN_LAYOUT) {
-                               os << "{\\par";
-                               column += 4;
+                       } else if (align != LYX_ALIGN_LAYOUT && next) {
+                               // We do not need \par here (Dekel)
+                               // os << "{\\par";
+                               os << "{";
+                               ++column;
                                return_value = true;
                        }
 
@@ -2565,6 +2602,8 @@ bool LyXParagraph::SimpleTeXOnePar(Buffer const * buf,
                        case LYX_ALIGN_SPECIAL:
                                break;
                        case LYX_ALIGN_LEFT:
+                               if (moving_arg)
+                                       os << "\\protect";
                                if (getParLanguage(bparams)->babel() != "hebrew") {
                                        os << "\\raggedright ";
                                        column+= 13;
@@ -2574,6 +2613,8 @@ bool LyXParagraph::SimpleTeXOnePar(Buffer const * buf,
                                }
                                break;
                        case LYX_ALIGN_RIGHT:
+                               if (moving_arg)
+                                       os << "\\protect";
                                if (getParLanguage(bparams)->babel() != "hebrew") {
                                        os << "\\raggedleft ";
                                        column+= 12;
@@ -2583,6 +2624,8 @@ bool LyXParagraph::SimpleTeXOnePar(Buffer const * buf,
                                }
                                break;
                        case LYX_ALIGN_CENTER:
+                               if (moving_arg)
+                                       os << "\\protect";
                                os << "\\centering ";
                                column+= 11;
                                break;
@@ -3984,7 +4027,7 @@ string const LyXParagraph::String(Buffer const * buffer,
                s += labelstring + ' ';
 
        for (LyXParagraph::size_type i = beg; i < end; ++i) {
-               value_type c = GetChar(i);
+               value_type c = GetUChar(buffer->params, i);
                if (IsPrintable(c))
                        s += c;
                else if (c == META_INSET) {
@@ -4037,3 +4080,16 @@ void LyXParagraph::resizeInsetsLyXText(BufferView * bv)
                }
        }
 }
+
+
+void LyXParagraph::fitToSize()
+{
+       TextContainer tmp(text.begin(), text.end());
+       text.swap(tmp);
+}
+
+
+void LyXParagraph::setContentsFromPar(LyXParagraph * par)
+{
+       text = par->text;
+}