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 Row::Row(Paragraph * pa, pos_type po)
32 : par_(pa), pos_(po), fill_(0), height_(0), width_(0),
33 ascent_of_text_(0), baseline_(0), next_(0), previous_(0)
37 Paragraph * Row::par()
43 Paragraph * Row::par() const
49 unsigned short Row::height() const
55 Row * Row::next() const
61 void Row::par(Paragraph * p)
67 void Row::pos(pos_type p)
73 pos_type Row::pos() const
91 void Row::height(unsigned short h)
97 void Row::width(unsigned int w)
103 unsigned int Row::width() const
109 void Row::ascent_of_text(unsigned short a)
115 unsigned short Row::ascent_of_text() const
117 return ascent_of_text_;
121 void Row::top_of_text(unsigned int top)
127 unsigned int Row::top_of_text() const
133 void Row::baseline(unsigned int b)
139 unsigned int Row::baseline() const
145 void Row::next(Row * r)
151 void Row::previous(Row * r)
157 Row * Row::previous() const
163 bool Row::isParStart() const
169 bool Row::isParEnd() const
171 return !next() || next()->par() != par();
175 pos_type Row::lastPos() const
181 return par()->size() - 1;
183 return next()->pos() - 1;
190 bool nextRowIsAllInset(Row const & row, pos_type last)
192 if (last + 1 >= row.par()->size())
195 if (!row.par()->isInset(last + 1))
198 Inset * i = row.par()->getInset(last + 1);
199 return i->needFullRow() || i->display();
205 pos_type Row::lastPrintablePos() const
207 pos_type const last = lastPos();
209 // if this row is an end of par, just act like lastPos()
213 bool const nextrownotinset = !nextRowIsAllInset(*this, last);
215 if (nextrownotinset && par()->isSeparator(last))
222 int Row::numberOfSeparators() const
224 pos_type const last = lastPrintablePos();
225 pos_type p = max(pos(), par()->beginningOfBody());
228 for (; p < last; ++p) {
229 if (par()->isSeparator(p)) {
237 int Row::numberOfHfills() const
239 pos_type const last = lastPos();
240 pos_type first = pos();
242 // hfill *DO* count at the beginning of paragraphs!
244 while (first < last && par()->isHfill(first)) {
249 first = max(first, par()->beginningOfBody());
253 // last, because the end is ignored!
254 for (pos_type p = first; p < last; ++p) {
255 if (par()->isHfill(p))
262 int Row::numberOfLabelHfills() const
264 pos_type last = lastPos();
265 pos_type first = pos();
267 // hfill *DO* count at the beginning of paragraphs!
269 while (first < last && par()->isHfill(first))
273 last = min(last, par()->beginningOfBody());
276 // last, because the end is ignored!
277 for (pos_type p = first; p < last; ++p) {
278 if (par()->isHfill(p))
285 bool Row::hfillExpansion(pos_type pos) const
287 if (!par()->isHfill(pos))
290 // at the end of a row it does not count
291 // unless another hfill exists on the line
292 if (pos >= lastPos()) {
293 pos_type i = this->pos();
294 while (i < pos && !par()->isHfill(i)) {
302 // at the beginning of a row it does not count, if it is not
303 // the first row of a paragaph
307 // in some labels it does not count
308 if (par()->layout()->margintype != MARGIN_MANUAL
309 && pos < par()->beginningOfBody())
312 // if there is anything between the first char of the row and
313 // the specified position that is not a newline and not a hfill,
314 // the hfill will count, otherwise not
315 pos_type i = this->pos();
316 while (i < pos && (par()->isNewline(i) || par()->isHfill(i)))