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"
20 #include "Paragraph.h"
26 pos_type Bidi::log2vis(pos_type pos) const
28 return (start_ == -1) ? pos : log2vis_list_[pos - start_];
32 pos_type Bidi::vis2log(pos_type pos) const
34 return (start_ == -1) ? pos : vis2log_list_[pos - start_];
38 pos_type Bidi::level(pos_type pos) const
40 return (start_ == -1) ? 0 : levels_[pos - start_];
44 bool Bidi::inRange(pos_type pos) const
46 return start_ == -1 || (start_ <= pos && pos <= end_);
50 bool Bidi::same_direction() const
52 return same_direction_;
56 void Bidi::computeTables(Paragraph const & par,
57 Buffer const & buf, Row const & row)
59 same_direction_ = true;
60 if (!lyxrc.rtl_support) {
65 if (par.inInset().forceLTR()) {
71 end_ = row.endpos() - 1;
78 if (end_ + 2 - start_ >
79 static_cast<pos_type>(log2vis_list_.size())) {
81 (end_ + 2 - start_ < 500) ?
82 500 : 2 * (end_ + 2 - start_);
83 log2vis_list_.resize(new_size);
84 vis2log_list_.resize(new_size);
85 levels_.resize(new_size);
88 vis2log_list_[end_ + 1 - start_] = -1;
89 log2vis_list_[end_ + 1 - start_] = -1;
91 BufferParams const & bufparams = buf.params();
93 bool const rtl_par = par.isRTL(bufparams);
97 pos_type const body_pos = par.beginOfBody();
99 for (pos_type lpos = start_; lpos <= end_; ++lpos) {
100 bool is_space = false;
101 // We do not handle spaces around an RTL segment in a special way anymore.
102 // Neither do we do so when generating the LaTeX, so setting is_space
103 // to false makes the view in the GUI consistent with the output of LaTeX
104 // later. The old setting was:
105 //bool is_space = par.isLineSeparator(lpos);
106 // FIXME: once we're sure that this is what we really want, we should just
107 // get rid of this variable...
109 (is_space && lpos + 1 <= end_ &&
110 !par.isLineSeparator(lpos + 1) &&
111 !par.isNewline(lpos + 1))
114 Font const * font = &(par.getFontSettings(bufparams, pos));
115 if (pos != lpos && 0 < lpos && rtl0 && font->isRightToLeft() &&
116 font->fontInfo().number() == FONT_ON &&
117 par.getFontSettings(bufparams, lpos - 1).fontInfo().number()
119 font = &(par.getFontSettings(bufparams, lpos));
122 bool new_rtl = font->isVisibleRightToLeft();
123 bool new_rtl0 = font->isRightToLeft();
127 if (lpos == body_pos - 1
128 && row.pos() < body_pos - 1
130 new_level = rtl_par ? 1 : 0;
133 } else if (new_rtl0) {
134 new_level = new_rtl ? 1 : 2;
136 new_level = rtl_par ? 2 : 0;
139 if (is_space && new_level >= lev) {
145 int new_level2 = new_level;
147 if (lev == new_level && rtl0 != new_rtl0) {
149 log2vis_list_[lpos - start_] = rtl ? 1 : -1;
150 } else if (lev < new_level) {
151 log2vis_list_[lpos - start_] = rtl ? -1 : 1;
152 if (new_level > 0 && !rtl_par)
153 same_direction_ = false;
155 log2vis_list_[lpos - start_] = new_rtl ? -1 : 1;
159 levels_[lpos - start_] = new_level;
161 while (lev > new_level2) {
162 pos_type old_lpos = stack[--lev];
163 int delta = lpos - old_lpos - 1;
166 log2vis_list_[lpos - start_] += delta;
167 log2vis_list_[old_lpos - start_] += delta;
169 while (lev < new_level)
174 pos_type const old_lpos = stack[--lev];
175 int delta = end_ - old_lpos;
178 log2vis_list_[old_lpos - start_] += delta;
181 pos_type vpos = start_ - 1;
182 for (pos_type lpos = start_; lpos <= end_; ++lpos) {
183 vpos += log2vis_list_[lpos - start_];
184 vis2log_list_[vpos - start_] = lpos;
185 log2vis_list_[lpos - start_] = vpos;
190 // This method requires a previous call to computeTables()
191 bool Bidi::isBoundary(Buffer const & buf, Paragraph const & par,
194 if (!lyxrc.rtl_support || pos == 0)
197 if (!inRange(pos - 1)) {
198 // This can happen if pos is the first char of a row.
199 // Returning false in this case is incorrect!
203 bool const rtl = level(pos - 1) % 2;
204 bool const rtl2 = inRange(pos)
206 : par.isRTL(buf.params());
211 bool Bidi::isBoundary(Buffer const & buf, Paragraph const & par,
212 pos_type pos, Font const & font) const
214 if (!lyxrc.rtl_support)
215 return false; // This is just for speedup
217 bool const rtl = font.isVisibleRightToLeft();
218 bool const rtl2 = inRange(pos)
220 : par.isRTL(buf.params());
225 bool reverseDirectionNeeded(Cursor const & cur)
228 * We determine the directions based on the direction of the
229 * bottom() --- i.e., outermost --- paragraph, because that is
230 * the only way to achieve consistency of the arrow's movements
231 * within a paragraph, and thus avoid situations in which the
234 return cur.bottom().paragraph().isRTL(cur.bv().buffer().params());
238 bool isWithinRtlParagraph(Cursor const & cur)
240 return cur.innerParagraph().isRTL(cur.bv().buffer().params());