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 (!row.par()->isInset(last + 1))
165 Inset * i = row.par()->getInset(last + 1);
166 return i->needFullRow() || i->display();
172 pos_type Row::lastPrintablePos() const
174 pos_type const last = lastPos();
176 // if this row is an end of par, just act like lastPos()
180 bool const nextrownotinset = !nextRowIsAllInset(*this, last);
182 if (nextrownotinset && par()->isSeparator(last))
189 int Row::numberOfSeparators() const
191 pos_type const last = lastPrintablePos();
192 pos_type p = max(pos(), par()->beginningOfMainBody());
195 for (; p <= last; ++p) {
196 if (par()->isSeparator(p)) {
204 int Row::numberOfHfills() const
206 pos_type const last = lastPos();
207 pos_type first = pos();
209 // hfill *DO* count at the beginning of paragraphs!
211 while (first <= last && par()->isHfill(first)) {
216 first = max(first, par()->beginningOfMainBody());
220 // last, because the end is ignored!
221 for (pos_type p = first; p <= last; ++p) {
222 if (par()->isHfill(p))
229 int Row::numberOfLabelHfills() const
231 pos_type last = lastPos();
232 pos_type first = pos();
234 // hfill *DO* count at the beginning of paragraphs!
236 while (first < last && par()->isHfill(first))
240 last = min(last, par()->beginningOfMainBody());
243 // last, because the end is ignored!
244 for (pos_type p = first; p < last; ++p) {
245 if (par()->isHfill(p))
252 bool Row::hfillExpansion(pos_type pos) const
254 if (!par()->isHfill(pos))
257 // at the end of a row it does not count
258 // unless another hfill exists on the line
259 if (pos >= lastPos()) {
260 pos_type i = this->pos();
261 while (i < pos && !par()->isHfill(i)) {
269 // at the beginning of a row it does not count, if it is not
270 // the first row of a paragaph
274 // in some labels it does not count
275 if (par()->layout()->margintype != MARGIN_MANUAL
276 && pos < par()->beginningOfMainBody())
279 // if there is anything between the first char of the row and
280 // the sepcified position that is not a newline and not a hfill,
281 // the hfill will count, otherwise not
282 pos_type i = this->pos();
283 while (i < pos && (par()->isNewline(i)
284 || par()->isHfill(i)))