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.
16 #include "lyxrow_funcs.h"
18 #include "paragraph.h"
20 #include "insets/updatableinset.h"
25 lyx::pos_type Bidi::log2vis(lyx::pos_type pos) const
27 return (start_ == -1) ? pos : log2vis_list_[pos - start_];
31 lyx::pos_type Bidi::vis2log(lyx::pos_type pos) const
33 return (start_ == -1) ? pos : vis2log_list_[pos - start_];
37 lyx::pos_type Bidi::level(lyx::pos_type pos) const
39 return (start_ == -1) ? 0 : levels_[pos - start_];
43 bool Bidi::inRange(lyx::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 & row)
57 same_direction_ = true;
58 if (!lyxrc.rtl_support) {
63 InsetOld * inset = par.inInset();
64 if (inset && inset->owner() &&
65 inset->owner()->lyxCode() == InsetOld::ERT_CODE) {
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.isRightToLeftPar(bufparams);
97 pos_type const body_pos = par.beginOfBody();
99 for (pos_type lpos = start_; lpos <= end_; ++lpos) {
100 bool is_space = par.isLineSeparator(lpos);
102 (is_space && lpos + 1 <= end_ &&
103 !par.isLineSeparator(lpos + 1) &&
104 !par.isNewline(lpos + 1))
106 LyXFont font = par.getFontSettings(bufparams, pos);
107 if (pos != lpos && 0 < lpos && rtl0 && font.isRightToLeft() &&
108 font.number() == LyXFont::ON &&
109 par.getFontSettings(bufparams, lpos - 1).number()
111 font = par.getFontSettings(bufparams, lpos);
115 bool new_rtl = font.isVisibleRightToLeft();
116 bool new_rtl0 = font.isRightToLeft();
119 if (lpos == body_pos - 1
120 && row.pos() < body_pos - 1
122 new_level = rtl_par ? 1 : 0;
126 new_level = new_rtl ? 1 : 2;
128 new_level = rtl_par ? 2 : 0;
130 if (is_space && new_level >= lev) {
136 int new_level2 = new_level;
138 if (lev == new_level && rtl0 != new_rtl0) {
140 log2vis_list_[lpos - start_] = rtl ? 1 : -1;
141 } else if (lev < new_level) {
142 log2vis_list_[lpos - start_] = rtl ? -1 : 1;
143 if (new_level > rtl_par)
144 same_direction_ = false;
146 log2vis_list_[lpos - start_] = new_rtl ? -1 : 1;
149 levels_[lpos - start_] = new_level;
151 while (lev > new_level2) {
152 pos_type old_lpos = stack[--lev];
153 int delta = lpos - old_lpos - 1;
156 log2vis_list_[lpos - start_] += delta;
157 log2vis_list_[old_lpos - start_] += delta;
159 while (lev < new_level)
164 pos_type const old_lpos = stack[--lev];
165 int delta = end_ - old_lpos;
168 log2vis_list_[old_lpos - start_] += delta;
171 pos_type vpos = start_ - 1;
172 for (pos_type lpos = start_; lpos <= end_; ++lpos) {
173 vpos += log2vis_list_[lpos - start_];
174 vis2log_list_[vpos - start_] = lpos;
175 log2vis_list_[lpos - start_] = vpos;
180 // This method requires a previous call to computeTables()
181 bool Bidi::isBoundary(Buffer const & buf, Paragraph const & par,
184 if (!lyxrc.rtl_support || pos == 0)
187 if (!inRange(pos - 1)) {
188 // This can happen if pos is the first char of a row.
189 // Returning false in this case is incorrect!
193 bool const rtl = level(pos - 1) % 2;
194 bool const rtl2 = inRange(pos)
196 : par.isRightToLeftPar(buf.params());
201 bool Bidi::isBoundary(Buffer const & buf, Paragraph const & par,
202 pos_type pos, LyXFont const & font) const
204 if (!lyxrc.rtl_support)
205 return false; // This is just for speedup
207 bool const rtl = font.isVisibleRightToLeft();
208 bool const rtl2 = inRange(pos)
210 : par.isRightToLeftPar(buf.params());