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 pos_type Row::lastPos() const
138 if (!next() || next()->par() != par()) {
139 return par()->size() - 1;
141 return next()->pos() - 1;
148 bool nextRowIsAllInset(Row const & row, pos_type last)
150 if (!row.par()->isInset(last + 1))
153 Inset * i = row.par()->getInset(last + 1);
154 return i->needFullRow() || i->display();
160 pos_type Row::lastPrintablePos() const
162 pos_type const last = lastPos();
164 // if this row is an end of par, just act like lastPos()
165 if (!next() || par() != next()->par())
168 bool const nextrownotinset = !nextRowIsAllInset(*this, last);
170 if (nextrownotinset && par()->isSeparator(last))
177 int Row::numberOfSeparators() const
179 pos_type const last = lastPrintablePos();
180 pos_type p = max(pos(), par()->beginningOfMainBody());
183 for (; p <= last; ++p) {
184 if (par()->isSeparator(p)) {
192 int Row::numberOfHfills() const
194 pos_type const last = lastPos();
195 pos_type first = pos();
197 // hfill *DO* count at the beginning of paragraphs!
199 while (first <= last && par()->isHfill(first)) {
204 first = max(first, par()->beginningOfMainBody());
208 // last, because the end is ignored!
209 for (pos_type p = first; p <= last; ++p) {
210 if (par()->isHfill(p))
217 int Row::numberOfLabelHfills() const
219 pos_type last = lastPos();
220 pos_type first = pos();
222 // hfill *DO* count at the beginning of paragraphs!
224 while (first < last && par()->isHfill(first))
228 last = min(last, par()->beginningOfMainBody());
231 // last, because the end is ignored!
232 for (pos_type p = first; p < last; ++p) {
233 if (par()->isHfill(p))
240 bool Row::hfillExpansion(pos_type pos) const
242 if (!par()->isHfill(pos))
245 // at the end of a row it does not count
246 // unless another hfill exists on the line
247 if (pos >= lastPos()) {
248 pos_type i = this->pos();
249 while (i < pos && !par()->isHfill(i)) {
257 // at the beginning of a row it does not count, if it is not
258 // the first row of a paragaph
262 // in some labels it does not count
263 if (par()->layout()->margintype != MARGIN_MANUAL
264 && pos < par()->beginningOfMainBody())
267 // if there is anything between the first char of the row and
268 // the sepcified position that is not a newline and not a hfill,
269 // the hfill will count, otherwise not
270 pos_type i = this->pos();
271 while (i < pos && (par()->isNewline(i)
272 || par()->isHfill(i)))