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"
24 lyx::pos_type Bidi::log2vis(lyx::pos_type pos) const
26 return (start_ == -1) ? pos : log2vis_list_[pos - start_];
30 lyx::pos_type Bidi::vis2log(lyx::pos_type pos) const
32 return (start_ == -1) ? pos : vis2log_list_[pos - start_];
36 lyx::pos_type Bidi::level(lyx::pos_type pos) const
38 return (start_ == -1) ? 0 : levels_[pos - start_];
42 bool Bidi::inRange(lyx::pos_type pos) const
44 return start_ == -1 || (start_ <= pos && pos <= end_);
47 bool Bidi::same_direction() const
49 return same_direction_;
53 void Bidi::computeTables(Paragraph const & par,
54 Buffer const & buf, Row const & row)
56 same_direction_ = true;
57 if (!lyxrc.rtl_support) {
62 if (par.ownerCode() == InsetBase::ERT_CODE) {
68 end_ = row.endpos() - 1;
75 if (end_ + 2 - start_ >
76 static_cast<pos_type>(log2vis_list_.size())) {
78 (end_ + 2 - start_ < 500) ?
79 500 : 2 * (end_ + 2 - start_);
80 log2vis_list_.resize(new_size);
81 vis2log_list_.resize(new_size);
82 levels_.resize(new_size);
85 vis2log_list_[end_ + 1 - start_] = -1;
86 log2vis_list_[end_ + 1 - start_] = -1;
88 BufferParams const & bufparams = buf.params();
90 bool const rtl_par = par.isRightToLeftPar(bufparams);
94 pos_type const body_pos = par.beginOfBody();
96 for (pos_type lpos = start_; lpos <= end_; ++lpos) {
97 bool is_space = par.isLineSeparator(lpos);
99 (is_space && lpos + 1 <= end_ &&
100 !par.isLineSeparator(lpos + 1) &&
101 !par.isNewline(lpos + 1))
103 LyXFont font = par.getFontSettings(bufparams, pos);
104 if (pos != lpos && 0 < lpos && rtl0 && font.isRightToLeft() &&
105 font.number() == LyXFont::ON &&
106 par.getFontSettings(bufparams, lpos - 1).number()
108 font = par.getFontSettings(bufparams, lpos);
112 bool new_rtl = font.isVisibleRightToLeft();
113 bool new_rtl0 = font.isRightToLeft();
116 if (lpos == body_pos - 1
117 && row.pos() < body_pos - 1
119 new_level = rtl_par ? 1 : 0;
123 new_level = new_rtl ? 1 : 2;
125 new_level = rtl_par ? 2 : 0;
127 if (is_space && new_level >= lev) {
133 int new_level2 = new_level;
135 if (lev == new_level && rtl0 != new_rtl0) {
137 log2vis_list_[lpos - start_] = rtl ? 1 : -1;
138 } else if (lev < new_level) {
139 log2vis_list_[lpos - start_] = rtl ? -1 : 1;
140 if (new_level > rtl_par)
141 same_direction_ = false;
143 log2vis_list_[lpos - start_] = new_rtl ? -1 : 1;
146 levels_[lpos - start_] = new_level;
148 while (lev > new_level2) {
149 pos_type old_lpos = stack[--lev];
150 int delta = lpos - old_lpos - 1;
153 log2vis_list_[lpos - start_] += delta;
154 log2vis_list_[old_lpos - start_] += delta;
156 while (lev < new_level)
161 pos_type const old_lpos = stack[--lev];
162 int delta = end_ - old_lpos;
165 log2vis_list_[old_lpos - start_] += delta;
168 pos_type vpos = start_ - 1;
169 for (pos_type lpos = start_; lpos <= end_; ++lpos) {
170 vpos += log2vis_list_[lpos - start_];
171 vis2log_list_[vpos - start_] = lpos;
172 log2vis_list_[lpos - start_] = vpos;
177 // This method requires a previous call to computeTables()
178 bool Bidi::isBoundary(Buffer const & buf, Paragraph const & par,
181 if (!lyxrc.rtl_support || pos == 0)
184 if (!inRange(pos - 1)) {
185 // This can happen if pos is the first char of a row.
186 // Returning false in this case is incorrect!
190 bool const rtl = level(pos - 1) % 2;
191 bool const rtl2 = inRange(pos)
193 : par.isRightToLeftPar(buf.params());
198 bool Bidi::isBoundary(Buffer const & buf, Paragraph const & par,
199 pos_type pos, LyXFont const & font) const
201 if (!lyxrc.rtl_support)
202 return false; // This is just for speedup
204 bool const rtl = font.isVisibleRightToLeft();
205 bool const rtl2 = inRange(pos)
207 : par.isRightToLeftPar(buf.params());