]> git.lyx.org Git - lyx.git/blobdiff - src/Bidi.cpp
#5502 add binding for full screen toggle on mac
[lyx.git] / src / Bidi.cpp
index 37cb87520a1e0f31b5a1ce84ef7e9d6bbf3fcc8a..3b598a4fbd1087c3969a091889328077d4957123 100644 (file)
@@ -13,6 +13,7 @@
 #include "Bidi.h"
 #include "Buffer.h"
 #include "BufferView.h"
+#include "Cursor.h"
 #include "Font.h"
 #include "Row.h"
 #include "LyXRC.h"
@@ -45,6 +46,7 @@ bool Bidi::inRange(pos_type pos) const
        return start_ == -1 || (start_ <= pos && pos <= end_);
 }
 
+
 bool Bidi::same_direction() const
 {
        return same_direction_;
@@ -55,12 +57,8 @@ void Bidi::computeTables(Paragraph const & par,
        Buffer const & buf, Row const & row)
 {
        same_direction_ = true;
-       if (!lyxrc.rtl_support) {
-               start_ = -1;
-               return;
-       }
 
-       if (par.ownerCode() == Inset::ERT_CODE || par.ownerCode() == Inset::LISTINGS_CODE) {
+       if (par.inInset().forceLTR()) {
                start_ = -1;
                return;
        }
@@ -88,7 +86,7 @@ void Bidi::computeTables(Paragraph const & par,
 
        BufferParams const & bufparams = buf.params();
        pos_type stack[2];
-       bool const rtl_par = par.isRightToLeftPar(bufparams);
+       bool const rtl_par = par.isRTL(bufparams);
        int lev = 0;
        bool rtl = false;
        bool rtl0 = false;
@@ -106,19 +104,21 @@ void Bidi::computeTables(Paragraph const & par,
                pos_type const pos =
                        (is_space && lpos + 1 <= end_ &&
                         !par.isLineSeparator(lpos + 1) &&
+                        !par.isEnvSeparator(lpos + 1) &&
                         !par.isNewline(lpos + 1))
                        ? lpos + 1 : lpos;
-               Font font = par.getFontSettings(bufparams, pos);
-               if (pos != lpos && 0 < lpos && rtl0 && font.isRightToLeft() &&
-                   font.number() == Font::ON &&
-                   par.getFontSettings(bufparams, lpos - 1).number()
-                   == Font::ON) {
-                       font = par.getFontSettings(bufparams, lpos);
+
+               Font const * font = &(par.getFontSettings(bufparams, pos));
+               if (pos != lpos && 0 < lpos && rtl0 && font->isRightToLeft() &&
+                   font->fontInfo().number() == FONT_ON &&
+                   par.getFontSettings(bufparams, lpos - 1).fontInfo().number()
+                   == FONT_ON) {
+                       font = &(par.getFontSettings(bufparams, lpos));
                        is_space = false;
                }
+               bool new_rtl = font->isVisibleRightToLeft();
+               bool new_rtl0 = font->isRightToLeft();
 
-               bool new_rtl = font.isVisibleRightToLeft();
-               bool new_rtl0 = font.isRightToLeft();
                int new_level;
 
                if (lpos == body_pos - 1
@@ -127,10 +127,11 @@ void Bidi::computeTables(Paragraph const & par,
                        new_level = rtl_par ? 1 : 0;
                        new_rtl0 = rtl_par;
                        new_rtl = rtl_par;
-               } else if (new_rtl0)
+               } else if (new_rtl0) {
                        new_level = new_rtl ? 1 : 2;
-               else
+               } else {
                        new_level = rtl_par ? 2 : 0;
+               }
 
                if (is_space && new_level >= lev) {
                        new_level = lev;
@@ -147,8 +148,9 @@ void Bidi::computeTables(Paragraph const & par,
                        log2vis_list_[lpos - start_] = rtl ? -1 : 1;
                        if (new_level > 0 && !rtl_par)
                                same_direction_ = false;
-               } else
+               } else {
                        log2vis_list_[lpos - start_] = new_rtl ? -1 : 1;
+               }
                rtl = new_rtl;
                rtl0 = new_rtl0;
                levels_[lpos - start_] = new_level;
@@ -186,7 +188,7 @@ void Bidi::computeTables(Paragraph const & par,
 bool Bidi::isBoundary(Buffer const & buf, Paragraph const & par,
        pos_type pos) const
 {
-       if (!lyxrc.rtl_support || pos == 0)
+       if (pos == 0)
                return false;
 
        if (!inRange(pos - 1)) {
@@ -198,7 +200,7 @@ bool Bidi::isBoundary(Buffer const & buf, Paragraph const & par,
        bool const rtl = level(pos - 1) % 2;
        bool const rtl2 = inRange(pos)
                ? level(pos) % 2
-               : par.isRightToLeftPar(buf.params());
+               : par.isRTL(buf.params());
        return rtl != rtl2;
 }
 
@@ -206,13 +208,10 @@ bool Bidi::isBoundary(Buffer const & buf, Paragraph const & par,
 bool Bidi::isBoundary(Buffer const & buf, Paragraph const & par,
        pos_type pos, Font const & font) const
 {
-       if (!lyxrc.rtl_support)
-               return false;    // This is just for speedup
-
        bool const rtl = font.isVisibleRightToLeft();
        bool const rtl2 = inRange(pos)
                ? level(pos) % 2
-               : par.isRightToLeftPar(buf.params());
+               : par.isRTL(buf.params());
        return rtl != rtl2;
 }
 
@@ -226,15 +225,13 @@ bool reverseDirectionNeeded(Cursor const & cur)
         * within a paragraph, and thus avoid situations in which the
         * cursor gets stuck.
         */
-       return cur.bottom().paragraph().isRightToLeftPar(
-                       cur.bv().buffer()->params());
+       return cur.bottom().paragraph().isRTL(cur.bv().buffer().params());
 }
 
 
 bool isWithinRtlParagraph(Cursor const & cur)
 {
-       return cur.innerParagraph().isRightToLeftPar(
-               cur.bv().buffer()->params());
+       return cur.innerParagraph().isRTL(cur.bv().buffer().params());
 }
 
 } // namespace lyx