- bool is_first_word_in_row = true;
- int cw, lastWordWidth = 0;
- int maxWidth = getMaxTextWidth(pain, this, x);
-
- for(p = 0; p < par->Last(); ++p) {
- cw = SingleWidth(pain, par, p);
- width += cw;
- lastWordWidth += cw;
- SingleHeight(pain, par, p, asc, desc);
- wordAscent = max(wordAscent, asc);
- wordDescent = max(wordDescent, desc);
- if (par->IsNewline(p)) {
- if (!is_first_word_in_row && (width >= maxWidth)) {
- // we have to split also the row above
- rows.back().asc = oasc;
- rows.back().desc = odesc;
- row.pos = nwp;
- rows.push_back(row);
- oasc = wordAscent;
- odesc = wordDescent;
- insetWidth = max(insetWidth, owidth);
- width = lastWordWidth;
- lastWordWidth = 0;
- }
- rows.back().asc = wordAscent;
- rows.back().desc = wordDescent;
- row.pos = ++p;
- rows.push_back(row);
- SingleHeight(pain, par, p, oasc, odesc);
- insetWidth = max(insetWidth, owidth);
- width = 0;
- is_first_word_in_row = true;
- wordAscent = wordDescent = lastWordWidth = 0;
- nwp = p;
- continue;
- }
- Inset * inset = 0;
- if (((p + 1) < par->Last()) &&
- (par->GetChar(p + 1)==LyXParagraph::META_INSET))
- inset = par->GetInset(p + 1);
- if (inset) {
- inset->setOwner(const_cast<InsetText*>(this)); // is this safe?
- if (inset->display()) {
- if (!is_first_word_in_row && (width >= maxWidth)) {
- // we have to split also the row above
- rows.back().asc = oasc;
- rows.back().desc = odesc;
- row.pos = nwp;
- rows.push_back(row);
- oasc = wordAscent;
- odesc = wordDescent;
- insetWidth = max(insetWidth, owidth);
- width = lastWordWidth;
- lastWordWidth = 0;
- } else {
- oasc = max(oasc, wordAscent);
- odesc = max(odesc, wordDescent);
- }
- rows.back().asc = oasc;
- rows.back().desc = odesc;
- row.pos = ++p;
- rows.push_back(row);
- SingleHeight(pain, par, p, asc, desc);
- rows.back().asc = asc;
- rows.back().desc = desc;
- row.pos = nwp = p + 1;
- rows.push_back(row);
- oasc = odesc = width = lastWordWidth = 0;
- is_first_word_in_row = true;
- wordAscent = wordDescent = 0;
- continue;
- }
- } else if (par->IsSeparator(p)) {
- if (width >= maxWidth) {
- if (is_first_word_in_row) {
- rows.back().asc = wordAscent;
- rows.back().desc = wordDescent;
- row.pos = p + 1;
- rows.push_back(row);
- oasc = odesc = width = 0;
- } else {
- rows.back().asc = oasc;
- rows.back().desc = odesc;
- row.pos = nwp;
- rows.push_back(row);
- oasc = wordAscent;
- odesc = wordDescent;
- insetWidth = max(insetWidth, owidth);
- width = lastWordWidth;
- }
- wordAscent = wordDescent = lastWordWidth = 0;
- nwp = p + 1;
- continue;
- }
- owidth = width;
- oasc = max(oasc, wordAscent);
- odesc = max(odesc, wordDescent);
- wordAscent = wordDescent = lastWordWidth = 0;
- nwp = p + 1;
- is_first_word_in_row = false;