]> git.lyx.org Git - lyx.git/blobdiff - src/Text.cpp
adjust
[lyx.git] / src / Text.cpp
index 8250030e36bbe4be22e037c9c90f4f056011b2ec..c6c1d1dc875536ebd27fa47c61feef20ca450f76 100644 (file)
@@ -45,6 +45,7 @@
 #include "paragraph_funcs.h"
 #include "ParagraphParameters.h"
 #include "Undo.h"
+#include "TextMetrics.h"
 #include "VSpace.h"
 #include "WordLangTuple.h"
 
@@ -68,6 +69,7 @@
 #include "support/convert.h"
 
 #include <boost/current_function.hpp>
+#include <boost/next_prior.hpp>
 
 #include <sstream>
 
@@ -356,7 +358,7 @@ double Text::spacing(Buffer const & buffer,
 }
 
 
-void Text::breakParagraph(Cursor & cur, bool keep_layout)
+void Text::breakParagraph(Cursor & cur, bool inverse_logic)
 {
        BOOST_ASSERT(this == cur.text());
 
@@ -381,11 +383,9 @@ void Text::breakParagraph(Cursor & cur, bool keep_layout)
                cpar.eraseChar(cur.pos(), cur.buffer().params().trackChanges);
 
        // What should the layout for the new paragraph be?
-       int preserve_layout = 0;
-       if (keep_layout)
-               preserve_layout = 2;
-       else
-               preserve_layout = layout->isEnvironment();
+       bool keep_layout = inverse_logic ? 
+               !layout->isEnvironment() 
+               : layout->isEnvironment();
 
        // We need to remember this before we break the paragraph, because
        // that invalidates the layout variable
@@ -395,7 +395,7 @@ void Text::breakParagraph(Cursor & cur, bool keep_layout)
        bool const isempty = cpar.allowEmpty() && cpar.empty();
 
        lyx::breakParagraph(cur.buffer().params(), paragraphs(), cpit,
-                        cur.pos(), preserve_layout);
+                        cur.pos(), keep_layout);
 
        // After this, neither paragraph contains any rows!
 
@@ -440,6 +440,7 @@ void Text::insertChar(Cursor & cur, char_type c)
 
        recordUndo(cur, Undo::INSERT);
 
+       TextMetrics const & tm = cur.bv().textMetrics(this);
        Buffer const & buffer = cur.buffer();
        Paragraph & par = cur.paragraph();
        // try to remove this
@@ -458,8 +459,8 @@ void Text::insertChar(Cursor & cur, char_type c)
                            !(contains(number_seperators, c) &&
                              cur.pos() != 0 &&
                              cur.pos() != cur.lastpos() &&
-                             getFont(buffer, par, cur.pos()).number() == Font::ON &&
-                             getFont(buffer, par, cur.pos() - 1).number() == Font::ON)
+                             tm.getDisplayFont(pit, cur.pos()).number() == Font::ON &&
+                             tm.getDisplayFont(pit, cur.pos() - 1).number() == Font::ON)
                           )
                                number(cur); // Set current_font.number to OFF
                } else if (isDigit(c) &&
@@ -473,11 +474,13 @@ void Text::insertChar(Cursor & cur, char_type c)
                                     || par.isSeparator(cur.pos() - 2)
                                     || par.isNewline(cur.pos() - 2))
                                  ) {
-                                       setCharFont(buffer, pit, cur.pos() - 1, cur.current_font);
+                                       setCharFont(buffer, pit, cur.pos() - 1, cur.current_font,
+                                               tm.font_);
                                } else if (contains(number_seperators, c)
                                     && cur.pos() >= 2
-                                    && getFont(buffer, par, cur.pos() - 2).number() == Font::ON) {
-                                       setCharFont(buffer, pit, cur.pos() - 1, cur.current_font);
+                                    && tm.getDisplayFont(pit, cur.pos() - 2).number() == Font::ON) {
+                                       setCharFont(buffer, pit, cur.pos() - 1, cur.current_font,
+                                               tm.font_);
                                }
                        }
                }
@@ -508,7 +511,7 @@ void Text::insertChar(Cursor & cur, char_type c)
        if ((cur.pos() >= 2) && (par.isLineSeparator(cur.pos() - 1))) {
                // get font in front and behind the space in question. But do NOT 
                // use getFont(cur.pos()) because the character c is not inserted yet
-               Font const & pre_space_font  = getFont(buffer, par, cur.pos() - 2);
+               Font const & pre_space_font  = tm.getDisplayFont(cur.pit(), cur.pos() - 2);
                Font const & post_space_font = cur.real_current_font;
                bool pre_space_rtl  = pre_space_font.isVisibleRightToLeft();
                bool post_space_rtl = post_space_font.isVisibleRightToLeft();
@@ -518,10 +521,10 @@ void Text::insertChar(Cursor & cur, char_type c)
                        // adjacent character whose direction is the paragraph's
                        // direction; don't touch other properties of the font
                        Language const * lang = 
-                               (pre_space_rtl == par.isRightToLeftPar(buffer.params())) ?
+                               (pre_space_rtl == par.isRTL(buffer.params())) ?
                                pre_space_font.language() : post_space_font.language();
 
-                       Font space_font = getFont(buffer, par, cur.pos() - 1);
+                       Font space_font = tm.getDisplayFont(cur.pit(), cur.pos() - 1);
                        space_font.setLanguage(lang);
                        par.setFont(cur.pos() - 1, space_font);
                }
@@ -1138,7 +1141,7 @@ bool Text::dissolveInset(Cursor & cur) {
                                        b.getLanguage());
                }
 
-               pasteParagraphList(cur, plist, b.params().getTextClass_ptr(),
+               pasteParagraphList(cur, plist, b.params().getTextClassPtr(),
                                   b.errorList("Paste"));
                // restore position
                cur.pit() = std::min(cur.lastpit(), spit);
@@ -1373,17 +1376,17 @@ docstring Text::getPossibleLabel(Cursor & cur) const
                name = from_ascii(layout->latexname());
 
        // for captions, we just take the caption type
-       Inset * caption_inset = cur.innerInsetOfType(Inset::CAPTION_CODE);
+       Inset * caption_inset = cur.innerInsetOfType(CAPTION_CODE);
        if (caption_inset)
                name = from_ascii(static_cast<InsetCaption *>(caption_inset)->type());
 
        // If none of the above worked, we'll see if we're inside various
        // types of insets and take our abbreviation from them.
        if (name.empty()) {
-               Inset::Code const codes[] = {
-                       Inset::FLOAT_CODE,
-                       Inset::WRAP_CODE,
-                       Inset::FOOT_CODE
+               InsetCode const codes[] = {
+                       FLOAT_CODE,
+                       WRAP_CODE,
+                       FOOT_CODE
                };
                for (unsigned int i = 0; i < (sizeof codes / sizeof codes[0]); ++i) {
                        Inset * float_inset = cur.innerInsetOfType(codes[i]);