X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FBidi.cpp;h=a85f3eaddd26d4c64b035293e8abf9b448e953db;hb=90f7007a2e6c78ffd031e4636ff909ab1bc2ddec;hp=df1f7495d6c11751b167d2cc0ceaec360e577d89;hpb=e9780fe317b3bad923dee327d68a06562c926029;p=lyx.git diff --git a/src/Bidi.cpp b/src/Bidi.cpp index df1f7495d6..a85f3eaddd 100644 --- a/src/Bidi.cpp +++ b/src/Bidi.cpp @@ -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_; @@ -60,7 +62,7 @@ void Bidi::computeTables(Paragraph const & par, return; } - if (par.ownerCode() == Inset::ERT_CODE || par.ownerCode() == Inset::LISTINGS_CODE) { + if (par.inInset().forceLTR()) { start_ = -1; return; } @@ -88,30 +90,38 @@ 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; pos_type const body_pos = par.beginOfBody(); for (pos_type lpos = start_; lpos <= end_; ++lpos) { - bool is_space = par.isLineSeparator(lpos); + bool is_space = false; + // We do not handle spaces around an RTL segment in a special way anymore. + // Neither do we do so when generating the LaTeX, so setting is_space + // to false makes the view in the GUI consistent with the output of LaTeX + // later. The old setting was: + //bool is_space = par.isLineSeparator(lpos); + // FIXME: once we're sure that this is what we really want, we should just + // get rid of this variable... pos_type const pos = (is_space && lpos + 1 <= end_ && !par.isLineSeparator(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 @@ -120,10 +130,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; @@ -140,8 +151,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; @@ -191,7 +203,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; } @@ -205,12 +217,12 @@ bool Bidi::isBoundary(Buffer const & buf, Paragraph const & par, bool const rtl = font.isVisibleRightToLeft(); bool const rtl2 = inRange(pos) ? level(pos) % 2 - : par.isRightToLeftPar(buf.params()); + : par.isRTL(buf.params()); return rtl != rtl2; } -bool reverseDirectionNeeded(Cursor const & cur) +bool reverseDirectionNeeded(Cursor const & cur) { /* * We determine the directions based on the direction of the @@ -219,15 +231,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