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;
61 if (par.inInset().forceLTR()) {
67 end_ = row.endpos() - 1;
74 if (end_ + 2 - start_ >
75 static_cast<pos_type>(log2vis_list_.size())) {
77 (end_ + 2 - start_ < 500) ?
78 500 : 2 * (end_ + 2 - start_);
79 log2vis_list_.resize(new_size);
80 vis2log_list_.resize(new_size);
81 levels_.resize(new_size);
84 vis2log_list_[end_ + 1 - start_] = -1;
85 log2vis_list_[end_ + 1 - start_] = -1;
87 BufferParams const & bufparams = buf.params();
89 bool const rtl_par = par.isRTL(bufparams);
93 pos_type const body_pos = par.beginOfBody();
95 for (pos_type lpos = start_; lpos <= end_; ++lpos) {
96 bool is_space = false;
97 // We do not handle spaces around an RTL segment in a special way anymore.
98 // Neither do we do so when generating the LaTeX, so setting is_space
99 // to false makes the view in the GUI consistent with the output of LaTeX
100 // later. The old setting was:
101 //bool is_space = par.isLineSeparator(lpos);
102 // FIXME: once we're sure that this is what we really want, we should just
103 // get rid of this variable...
105 (is_space && lpos + 1 <= end_ &&
106 !par.isLineSeparator(lpos + 1) &&
107 !par.isEnvSeparator(lpos + 1) &&
108 !par.isNewline(lpos + 1))
111 Font const * font = &(par.getFontSettings(bufparams, pos));
112 if (pos != lpos && 0 < lpos && rtl0 && font->isRightToLeft() &&
113 font->fontInfo().number() == FONT_ON &&
114 par.getFontSettings(bufparams, lpos - 1).fontInfo().number()
116 font = &(par.getFontSettings(bufparams, lpos));
119 bool new_rtl = font->isVisibleRightToLeft();
120 bool new_rtl0 = font->isRightToLeft();
124 if (lpos == body_pos - 1
125 && row.pos() < body_pos - 1
127 new_level = rtl_par ? 1 : 0;
130 } else if (new_rtl0) {
131 new_level = new_rtl ? 1 : 2;
133 new_level = rtl_par ? 2 : 0;
136 if (is_space && new_level >= lev) {
142 int new_level2 = new_level;
144 if (lev == new_level && rtl0 != new_rtl0) {
146 log2vis_list_[lpos - start_] = rtl ? 1 : -1;
147 } else if (lev < new_level) {
148 log2vis_list_[lpos - start_] = rtl ? -1 : 1;
149 if (new_level > 0 && !rtl_par)
150 same_direction_ = false;
152 log2vis_list_[lpos - start_] = new_rtl ? -1 : 1;
156 levels_[lpos - start_] = new_level;
158 while (lev > new_level2) {
159 pos_type old_lpos = stack[--lev];
160 int delta = lpos - old_lpos - 1;
163 log2vis_list_[lpos - start_] += delta;
164 log2vis_list_[old_lpos - start_] += delta;
166 while (lev < new_level)
171 pos_type const old_lpos = stack[--lev];
172 int delta = end_ - old_lpos;
175 log2vis_list_[old_lpos - start_] += delta;
178 pos_type vpos = start_ - 1;
179 for (pos_type lpos = start_; lpos <= end_; ++lpos) {
180 vpos += log2vis_list_[lpos - start_];
181 vis2log_list_[vpos - start_] = lpos;
182 log2vis_list_[lpos - start_] = vpos;
187 // This method requires a previous call to computeTables()
188 bool Bidi::isBoundary(Buffer const & buf, Paragraph const & par,
194 if (!inRange(pos - 1)) {
195 // This can happen if pos is the first char of a row.
196 // Returning false in this case is incorrect!
200 bool const rtl = level(pos - 1) % 2;
201 bool const rtl2 = inRange(pos)
203 : par.isRTL(buf.params());
208 bool Bidi::isBoundary(Buffer const & buf, Paragraph const & par,
209 pos_type pos, Font const & font) const
211 bool const rtl = font.isVisibleRightToLeft();
212 bool const rtl2 = inRange(pos)
214 : par.isRTL(buf.params());
219 bool reverseDirectionNeeded(Cursor const & cur)
222 * We determine the directions based on the direction of the
223 * bottom() --- i.e., outermost --- paragraph, because that is
224 * the only way to achieve consistency of the arrow's movements
225 * within a paragraph, and thus avoid situations in which the
228 return cur.bottom().paragraph().isRTL(cur.bv().buffer().params());
232 bool isWithinRtlParagraph(Cursor const & cur)
234 return cur.innerParagraph().isRTL(cur.bv().buffer().params());