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 Paragraph * Row::par()
37 Paragraph * Row::par() const
43 unsigned short Row::height() const
49 Row * Row::next() const
55 void Row::par(Paragraph * p)
61 void Row::pos(pos_type p)
67 pos_type Row::pos() const
85 void Row::height(unsigned short h)
91 void Row::width(unsigned int w)
97 unsigned int Row::width() const
103 void Row::ascent_of_text(unsigned short a)
109 unsigned short Row::ascent_of_text() const
111 return ascent_of_text_;
115 void Row::top_of_text(unsigned int top)
121 unsigned int Row::top_of_text() const
127 void Row::baseline(unsigned int b)
133 unsigned int Row::baseline() const
139 void Row::next(Row * r)
145 void Row::previous(Row * r)
151 Row * Row::previous() const
157 bool Row::isParStart() const
163 bool Row::isParEnd() const
165 return !next() || next()->par() != par();
169 pos_type Row::lastPos() const
175 return par()->size() - 1;
177 return next()->pos() - 1;
184 bool nextRowIsAllInset(Row const & row, pos_type last)
186 if (last + 1 >= row.par()->size())
189 if (!row.par()->isInset(last + 1))
192 Inset * i = row.par()->getInset(last + 1);
193 return i->needFullRow() || i->display();
199 pos_type Row::lastPrintablePos() const
201 pos_type const last = lastPos();
203 // if this row is an end of par, just act like lastPos()
207 bool const nextrownotinset = !nextRowIsAllInset(*this, last);
209 if (nextrownotinset && par()->isSeparator(last))
216 int Row::numberOfSeparators() const
218 pos_type const last = lastPrintablePos();
219 pos_type p = max(pos(), par()->beginningOfBody());
222 for (; p < last; ++p) {
223 if (par()->isSeparator(p)) {
231 int Row::numberOfHfills() const
233 pos_type const last = lastPos();
234 pos_type first = pos();
236 // hfill *DO* count at the beginning of paragraphs!
238 while (first < last && par()->isHfill(first)) {
243 first = max(first, par()->beginningOfBody());
247 // last, because the end is ignored!
248 for (pos_type p = first; p < last; ++p) {
249 if (par()->isHfill(p))
256 int Row::numberOfLabelHfills() const
258 pos_type last = lastPos();
259 pos_type first = pos();
261 // hfill *DO* count at the beginning of paragraphs!
263 while (first < last && par()->isHfill(first))
267 last = min(last, par()->beginningOfBody());
270 // last, because the end is ignored!
271 for (pos_type p = first; p < last; ++p) {
272 if (par()->isHfill(p))
279 bool Row::hfillExpansion(pos_type pos) const
281 if (!par()->isHfill(pos))
284 // at the end of a row it does not count
285 // unless another hfill exists on the line
286 if (pos >= lastPos()) {
287 pos_type i = this->pos();
288 while (i < pos && !par()->isHfill(i)) {
296 // at the beginning of a row it does not count, if it is not
297 // the first row of a paragaph
301 // in some labels it does not count
302 if (par()->layout()->margintype != MARGIN_MANUAL
303 && pos < par()->beginningOfBody())
306 // if there is anything between the first char of the row and
307 // the specified position that is not a newline and not a hfill,
308 // the hfill will count, otherwise not
309 pos_type i = this->pos();
310 while (i < pos && (par()->isNewline(i) || par()->isHfill(i)))