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
10 * Metrics for an on-screen text row.
16 #include "paragraph.h"
18 #include "lyxlayout.h"
26 : par_(0), pos_(0), fill_(0), height_(0), width_(0),
27 ascent_of_text_(0), baseline_(0), next_(0), previous_(0)
31 void Row::par(Paragraph * p)
37 void Row::pos(pos_type p)
43 pos_type Row::pos() const
61 void Row::height(unsigned short h)
67 void Row::width(unsigned int w)
73 unsigned int Row::width() const
79 void Row::ascent_of_text(unsigned short a)
85 unsigned short Row::ascent_of_text() const
87 return ascent_of_text_;
91 void Row::top_of_text(unsigned int top)
97 unsigned int Row::top_of_text() const
103 void Row::baseline(unsigned int b)
109 unsigned int Row::baseline() const
115 void Row::next(Row * r)
121 void Row::previous(Row * r)
127 Row * Row::previous() const
133 bool Row::isParStart() const
139 bool Row::isParEnd() const
141 return !next() || next()->par() != par();
145 pos_type Row::lastPos() const
151 return par()->size() - 1;
153 return next()->pos() - 1;
160 bool nextRowIsAllInset(Row const & row, pos_type last)
162 if (last + 1 >= row.par()->size())
165 if (!row.par()->isInset(last + 1))
168 Inset * i = row.par()->getInset(last + 1);
169 return i->needFullRow() || i->display();
175 pos_type Row::lastPrintablePos() const
177 pos_type const last = lastPos();
179 // if this row is an end of par, just act like lastPos()
183 bool const nextrownotinset = !nextRowIsAllInset(*this, last);
185 if (nextrownotinset && par()->isSeparator(last))
192 int Row::numberOfSeparators() const
194 pos_type const last = lastPrintablePos();
195 pos_type p = max(pos(), par()->beginningOfBody());
198 for (; p < last; ++p) {
199 if (par()->isSeparator(p)) {
207 int Row::numberOfHfills() const
209 pos_type const last = lastPos();
210 pos_type first = pos();
212 // hfill *DO* count at the beginning of paragraphs!
214 while (first < last && par()->isHfill(first)) {
219 first = max(first, par()->beginningOfBody());
223 // last, because the end is ignored!
224 for (pos_type p = first; p < last; ++p) {
225 if (par()->isHfill(p))
232 int Row::numberOfLabelHfills() const
234 pos_type last = lastPos();
235 pos_type first = pos();
237 // hfill *DO* count at the beginning of paragraphs!
239 while (first < last && par()->isHfill(first))
243 last = min(last, par()->beginningOfBody());
246 // last, because the end is ignored!
247 for (pos_type p = first; p < last; ++p) {
248 if (par()->isHfill(p))
255 bool Row::hfillExpansion(pos_type pos) const
257 if (!par()->isHfill(pos))
260 // at the end of a row it does not count
261 // unless another hfill exists on the line
262 if (pos >= lastPos()) {
263 pos_type i = this->pos();
264 while (i < pos && !par()->isHfill(i)) {
272 // at the beginning of a row it does not count, if it is not
273 // the first row of a paragaph
277 // in some labels it does not count
278 if (par()->layout()->margintype != MARGIN_MANUAL
279 && pos < par()->beginningOfBody())
282 // if there is anything between the first char of the row and
283 // the specified position that is not a newline and not a hfill,
284 // the hfill will count, otherwise not
285 pos_type i = this->pos();
286 while (i < pos && (par()->isNewline(i) || par()->isHfill(i)))