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)
153 if (row.par() != row.next()->par())
156 if (!row.par()->isInset(last + 1))
159 Inset * i = row.par()->getInset(last + 1);
160 return i->needFullRow() || i->display();
166 pos_type Row::lastPrintablePos() const
168 pos_type const last = lastPos();
169 bool const ignore_space_at_last = !nextRowIsAllInset(*this, last);
171 if (ignore_space_at_last && par()->isSeparator(last))
178 int Row::numberOfSeparators() const
180 pos_type const last = lastPrintablePos();
181 pos_type p = max(pos(), par()->beginningOfMainBody());
184 for (; p <= last; ++p) {
185 if (par()->isSeparator(p)) {
193 int Row::numberOfHfills() const
195 pos_type const last = lastPos();
196 pos_type first = pos();
198 // hfill *DO* count at the beginning of paragraphs!
200 while (first <= last && par()->isHfill(first)) {
205 first = max(first, par()->beginningOfMainBody());
209 // last, because the end is ignored!
210 for (pos_type p = first; p <= last; ++p) {
211 if (par()->isHfill(p))
218 int Row::numberOfLabelHfills() const
220 pos_type last = lastPos();
221 pos_type first = pos();
223 // hfill *DO* count at the beginning of paragraphs!
225 while (first < last && par()->isHfill(first))
229 last = min(last, par()->beginningOfMainBody());
232 // last, because the end is ignored!
233 for (pos_type p = first; p < last; ++p) {
234 if (par()->isHfill(p))
241 bool Row::hfillExpansion(pos_type pos) const
243 if (!par()->isHfill(pos))
246 // at the end of a row it does not count
247 // unless another hfill exists on the line
248 if (pos >= lastPos()) {
249 pos_type i = this->pos();
250 while (i < pos && !par()->isHfill(i)) {
258 // at the beginning of a row it does not count, if it is not
259 // the first row of a paragaph
263 // in some labels it does not count
264 if (par()->layout()->margintype != MARGIN_MANUAL
265 && pos < par()->beginningOfMainBody())
268 // if there is anything between the first char of the row and
269 // the sepcified position that is not a newline and not a hfill,
270 // the hfill will count, otherwise not
271 pos_type i = this->pos();
272 while (i < pos && (par()->isNewline(i)
273 || par()->isHfill(i)))