3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
15 #include "BufferView.h"
19 #include "Paragraph.h"
25 pos_type Bidi::log2vis(pos_type pos) const
27 return (start_ == -1) ? pos : log2vis_list_[pos - start_];
31 pos_type Bidi::vis2log(pos_type pos) const
33 return (start_ == -1) ? pos : vis2log_list_[pos - start_];
37 pos_type Bidi::level(pos_type pos) const
39 return (start_ == -1) ? 0 : levels_[pos - start_];
43 bool Bidi::inRange(pos_type pos) const
45 return start_ == -1 || (start_ <= pos && pos <= end_);
48 bool Bidi::same_direction() const
50 return same_direction_;
54 void Bidi::computeTables(Paragraph const & par,
55 Buffer const & buf, Row const & row)
57 same_direction_ = true;
58 if (!lyxrc.rtl_support) {
63 if (par.ownerCode() == Inset::ERT_CODE || par.ownerCode() == Inset::LISTINGS_CODE) {
69 end_ = row.endpos() - 1;
76 if (end_ + 2 - start_ >
77 static_cast<pos_type>(log2vis_list_.size())) {
79 (end_ + 2 - start_ < 500) ?
80 500 : 2 * (end_ + 2 - start_);
81 log2vis_list_.resize(new_size);
82 vis2log_list_.resize(new_size);
83 levels_.resize(new_size);
86 vis2log_list_[end_ + 1 - start_] = -1;
87 log2vis_list_[end_ + 1 - start_] = -1;
89 BufferParams const & bufparams = buf.params();
91 bool const rtl_par = par.isRightToLeftPar(bufparams);
95 pos_type const body_pos = par.beginOfBody();
97 for (pos_type lpos = start_; lpos <= end_; ++lpos) {
98 bool is_space = false;
99 // We do not handle spaces around an RTL segment in a special way anymore.
100 // Neither do we do so when generating the LaTeX, so setting is_space
101 // to false makes the view in the GUI consistent with the output of LaTeX
102 // later. The old setting was:
103 //bool is_space = par.isLineSeparator(lpos);
104 // FIXME: once we're sure that this is what we really want, we should just
105 // get rid of this variable...
107 (is_space && lpos + 1 <= end_ &&
108 !par.isLineSeparator(lpos + 1) &&
109 !par.isNewline(lpos + 1))
111 Font font = par.getFontSettings(bufparams, pos);
112 if (pos != lpos && 0 < lpos && rtl0 && font.isRightToLeft() &&
113 font.number() == Font::ON &&
114 par.getFontSettings(bufparams, lpos - 1).number()
116 font = par.getFontSettings(bufparams, lpos);
120 bool new_rtl = font.isVisibleRightToLeft();
121 bool new_rtl0 = font.isRightToLeft();
124 if (lpos == body_pos - 1
125 && row.pos() < body_pos - 1
127 new_level = rtl_par ? 1 : 0;
131 new_level = new_rtl ? 1 : 2;
133 new_level = rtl_par ? 2 : 0;
135 if (is_space && new_level >= lev) {
141 int new_level2 = new_level;
143 if (lev == new_level && rtl0 != new_rtl0) {
145 log2vis_list_[lpos - start_] = rtl ? 1 : -1;
146 } else if (lev < new_level) {
147 log2vis_list_[lpos - start_] = rtl ? -1 : 1;
148 if (new_level > 0 && !rtl_par)
149 same_direction_ = false;
151 log2vis_list_[lpos - start_] = new_rtl ? -1 : 1;
154 levels_[lpos - start_] = new_level;
156 while (lev > new_level2) {
157 pos_type old_lpos = stack[--lev];
158 int delta = lpos - old_lpos - 1;
161 log2vis_list_[lpos - start_] += delta;
162 log2vis_list_[old_lpos - start_] += delta;
164 while (lev < new_level)
169 pos_type const old_lpos = stack[--lev];
170 int delta = end_ - old_lpos;
173 log2vis_list_[old_lpos - start_] += delta;
176 pos_type vpos = start_ - 1;
177 for (pos_type lpos = start_; lpos <= end_; ++lpos) {
178 vpos += log2vis_list_[lpos - start_];
179 vis2log_list_[vpos - start_] = lpos;
180 log2vis_list_[lpos - start_] = vpos;
185 // This method requires a previous call to computeTables()
186 bool Bidi::isBoundary(Buffer const & buf, Paragraph const & par,
189 if (!lyxrc.rtl_support || pos == 0)
192 if (!inRange(pos - 1)) {
193 // This can happen if pos is the first char of a row.
194 // Returning false in this case is incorrect!
198 bool const rtl = level(pos - 1) % 2;
199 bool const rtl2 = inRange(pos)
201 : par.isRightToLeftPar(buf.params());
206 bool Bidi::isBoundary(Buffer const & buf, Paragraph const & par,
207 pos_type pos, Font const & font) const
209 if (!lyxrc.rtl_support)
210 return false; // This is just for speedup
212 bool const rtl = font.isVisibleRightToLeft();
213 bool const rtl2 = inRange(pos)
215 : par.isRightToLeftPar(buf.params());
220 bool reverseDirectionNeeded(Cursor const & cur)
223 * We determine the directions based on the direction of the
224 * bottom() --- i.e., outermost --- paragraph, because that is
225 * the only way to achieve consistency of the arrow's movements
226 * within a paragraph, and thus avoid situations in which the
229 return cur.bottom().paragraph().isRightToLeftPar(
230 cur.bv().buffer().params());
234 bool isWithinRtlParagraph(Cursor const & cur)
236 return cur.innerParagraph().isRightToLeftPar(
237 cur.bv().buffer().params());