diff --git a/src/ChangeLog b/src/ChangeLog index 28f2abe1cb..38b193773b 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2004-08-14 André Pönitz + + * text.C: + * text2.C: + * rowpainter.C: + * lyxtext.h (several functions): use a Paragraph & argument + instead of par_type + 2004-08-15 Jean-Marc Lasgouttes * metricsinfo.h: add a new field ltr_pos to PainterInfo diff --git a/src/FontIterator.C b/src/FontIterator.C index ad185696b8..e32886eace 100644 --- a/src/FontIterator.C +++ b/src/FontIterator.C @@ -21,7 +21,7 @@ FontIterator::FontIterator(LyXText const & text, lyx::par_type pit, lyx::pos_type pos) : text_(text), pit_(pit), pos_(pos), - font_(text.getFont(pit, pos)), + font_(text.getFont(text.getPar(pit), pos)), endspan_(text.getPar(pit).getEndPosOfFontSpan(pos)), bodypos_(text.getPar(pit).beginOfBody()) {} @@ -43,7 +43,7 @@ FontIterator & FontIterator::operator++() { ++pos_; if (pos_ > endspan_ || pos_ == bodypos_) { - font_ = text_.getFont(pit_, pos_); + font_ = text_.getFont(text_.getPar(pit_), pos_); endspan_ = text_.getPar(pit_).getEndPosOfFontSpan(pos_); } return *this; diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 0f33b7e527..541d38a563 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -1693,7 +1693,8 @@ bool InsetTabular::insertAsciiString(BufferView & bv, string const & buf, // we can only set this if we are not too far right if (cols < columns) { InsetText & inset = loctab->getCellInset(cell); - LyXFont const font = inset.text_.getFont(0, 0); + Paragraph & par = inset.text_.getPar(0); + LyXFont const font = inset.text_.getFont(par, 0); inset.setText(buf.substr(op, p - op), font); ++cols; ++cell; @@ -1703,7 +1704,8 @@ bool InsetTabular::insertAsciiString(BufferView & bv, string const & buf, // we can only set this if we are not too far right if (cols < columns) { InsetText & inset = tabular.getCellInset(cell); - LyXFont const font = inset.text_.getFont(0, 0); + Paragraph & par = inset.text_.getPar(0); + LyXFont const font = inset.text_.getFont(par, 0); inset.setText(buf.substr(op, p - op), font); } cols = ocol; @@ -1718,7 +1720,8 @@ bool InsetTabular::insertAsciiString(BufferView & bv, string const & buf, // check for the last cell if there is no trailing '\n' if (cell < cells && op < len) { InsetText & inset = loctab->getCellInset(cell); - LyXFont const font = inset.text_.getFont(0, 0); + Paragraph & par = inset.text_.getPar(0); + LyXFont const font = inset.text_.getFont(par, 0); inset.setText(buf.substr(op, len - op), font); } return true; diff --git a/src/lyxtext.h b/src/lyxtext.h index 965f8f990c..ceb03c23bf 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -59,11 +59,11 @@ public: /// update y coordinate cache of all paragraphs void updateParPositions(); /// - LyXFont getFont(par_type pit, pos_type pos) const; + LyXFont getFont(Paragraph const & par, pos_type pos) const; /// LyXFont getLayoutFont(par_type pit) const; /// - LyXFont getLabelFont(par_type pit) const; + LyXFont getLabelFont(Paragraph const & par) const; /// void setCharFont(par_type pit, pos_type pos, LyXFont const & font); /// @@ -271,9 +271,9 @@ public: InsetBase * checkInsetHit(int x, int y) const; /// - int singleWidth(par_type pit, pos_type pos) const; + int singleWidth(Paragraph const & par, pos_type pos) const; /// - int singleWidth(par_type pit, + int singleWidth(Paragraph const & par, pos_type pos, char c, LyXFont const & Font) const; /// return the color of the canvas @@ -399,7 +399,7 @@ private: /// sets row.width to the minimum space a row needs on the screen in pixel void setRowWidth(par_type pit, Row & row) const; /// the minimum space a manual label needs on the screen in pixels - int labelFill(par_type pit, Row const & row) const; + int labelFill(Paragraph const & par, Row const & row) const; /// FIXME int labelEnd(par_type pit) const; diff --git a/src/rowpainter.C b/src/rowpainter.C index f69d693f85..7f2694101b 100644 --- a/src/rowpainter.C +++ b/src/rowpainter.C @@ -104,7 +104,8 @@ private: Row & row_; /// Row's paragraph - mutable par_type pit_; + par_type const pit_; + Paragraph const & par_; // Looks ugly - is double xo_; @@ -120,12 +121,12 @@ private: RowPainter::RowPainter(BufferView const & bv, Painter & pain, LyXText const & text, par_type pit, RowList::iterator rit, int y) : bv_(bv), pain_(pain), text_(text), pars_(text.paragraphs()), - rit_(rit), row_(*rit), pit_(pit), + rit_(rit), row_(*rit), pit_(pit), par_(text.paragraphs()[pit]), xo_(text_.xo_), yo_(y), width_(text_.width()) { //lyxerr << "RowPainter: x: " << x_ << " xo: " << xo << " yo: " << yo // << " pit->y: " << pit_->y - // << " row: " << (pars_[pit_].size() ? pars_[pit_].getChar(row_.pos()) : 'X') << endl; + // << " row: " << (par_.size() ? par_.getChar(row_.pos()) : 'X') << endl; RowMetrics m = text_.computeRowMetrics(pit, row_); x_ = m.x + xo_; @@ -154,7 +155,7 @@ RowPainter::RowPainter(BufferView const & bv, Painter & pain, if (row_.pos() == 0) paintFirst(); - if (row_.endpos() >= pars_[pit_].size()) + if (row_.endpos() >= par_.size()) paintLast(); // paint text @@ -165,26 +166,26 @@ RowPainter::RowPainter(BufferView const & bv, Painter & pain, /// "temporary" LyXFont const RowPainter::getFont(pos_type pos) const { - return text_.getFont(pit_, pos); + return text_.getFont(par_, pos); } int RowPainter::singleWidth(lyx::pos_type pos) const { - return text_.singleWidth(pit_, pos); + return text_.singleWidth(par_, pos); } int RowPainter::singleWidth(lyx::pos_type pos, char c) const { - LyXFont const & font = text_.getFont(pit_, pos); - return text_.singleWidth(pit_, pos, c, font); + LyXFont const & font = text_.getFont(par_, pos); + return text_.singleWidth(par_, pos, c, font); } LyXFont const RowPainter::getLabelFont() const { - return text_.getLabelFont(pit_); + return text_.getLabelFont(par_); } @@ -196,7 +197,7 @@ int RowPainter::leftMargin() const void RowPainter::paintInset(pos_type const pos) { - InsetBase const * inset = pars_[pit_].getInset(pos); + InsetBase const * inset = par_.getInset(pos); BOOST_ASSERT(inset); PainterInfo pi(const_cast(&bv_), pain_); pi.base.font = getFont(pos); @@ -215,7 +216,7 @@ void RowPainter::paintHebrewComposeChar(pos_type & vpos) string str; // first char - char c = pars_[pit_].getChar(pos); + char c = par_.getChar(pos); str += c; ++vpos; @@ -224,7 +225,7 @@ void RowPainter::paintHebrewComposeChar(pos_type & vpos) int dx = 0; for (pos_type i = pos - 1; i >= 0; --i) { - c = pars_[pit_].getChar(i); + c = par_.getChar(i); if (!Encodings::IsComposeChar_hebrew(c)) { if (IsPrintableNonspace(c)) { int const width2 = singleWidth(i, c); @@ -248,8 +249,8 @@ void RowPainter::paintArabicComposeChar(pos_type & vpos) string str; // first char - char c = pars_[pit_].getChar(pos); - c = pars_[pit_].transformChar(c, pos); + char c = par_.getChar(pos); + c = par_.transformChar(c, pos); str += c; ++vpos; @@ -258,7 +259,7 @@ void RowPainter::paintArabicComposeChar(pos_type & vpos) int dx = 0; for (pos_type i = pos - 1; i >= 0; --i) { - c = pars_[pit_].getChar(i); + c = par_.getChar(i); if (!Encodings::IsComposeChar_arabic(c)) { if (IsPrintableNonspace(c)) { int const width2 = singleWidth(i, c); @@ -280,26 +281,26 @@ void RowPainter::paintChars(pos_type & vpos, bool hebrew, bool arabic) // first character string str; - str += pars_[pit_].getChar(pos); + str += par_.getChar(pos); if (arabic) { unsigned char c = str[0]; - str[0] = pars_[pit_].transformChar(c, pos); + str[0] = par_.transformChar(c, pos); } - bool prev_struckout = isDeletedText(pars_[pit_], pos); - bool prev_newtext = isInsertedText(pars_[pit_], pos); + bool prev_struckout = isDeletedText(par_, pos); + bool prev_newtext = isInsertedText(par_, pos); // collect as much similar chars as we can for (++vpos; vpos < end && (pos = text_.bidi.vis2log(vpos)) >= 0; ++vpos) { - char c = pars_[pit_].getChar(pos); + char c = par_.getChar(pos); if (!IsPrintableNonspace(c)) break; - if (prev_struckout != isDeletedText(pars_[pit_], pos)) + if (prev_struckout != isDeletedText(par_, pos)) break; - if (prev_newtext != isInsertedText(pars_[pit_], pos)) + if (prev_newtext != isInsertedText(par_, pos)) break; if (arabic && Encodings::IsComposeChar_arabic(c)) @@ -312,7 +313,7 @@ void RowPainter::paintChars(pos_type & vpos, bool hebrew, bool arabic) break; if (arabic) - c = pars_[pit_].transformChar(c, pos); + c = par_.transformChar(c, pos); str += c; } @@ -352,7 +353,7 @@ void RowPainter::paintFromPos(pos_type & vpos) double const orig_x = x_; - char const c = pars_[pit_].getChar(pos); + char const c = par_.getChar(pos); if (c == Paragraph::META_INSET) { paintInset(pos); @@ -396,7 +397,7 @@ void RowPainter::paintBackground() void RowPainter::paintSelection() { - bool const is_rtl = text_.isRTL(pars_[pit_]); + bool const is_rtl = text_.isRTL(par_); // the current selection LCursor const & cur = bv_.cursor(); @@ -408,7 +409,7 @@ void RowPainter::paintSelection() RowList::iterator endrow = pars_[endpit].getRow(cur.selEnd().pos()); int const h = row_.height(); - int const row_y = text_.yo_ + pars_[pit_].y + row_.y_offset(); + int const row_y = text_.yo_ + par_.y + row_.y_offset(); bool const sel_starts_here = startpit == pit_ && startrow == rit_; bool const sel_ends_here = endpit == pit_ && endrow == rit_; @@ -442,7 +443,7 @@ void RowPainter::paintSelection() pain_.fillRectangle(int(xo_), yo_, int(x_), h, LColor::selection); - pos_type const body_pos = pars_[pit_].beginOfBody(); + pos_type const body_pos = par_.beginOfBody(); pos_type const end = row_.endpos(); double tmpx = x_; @@ -450,24 +451,24 @@ void RowPainter::paintSelection() pos_type pos = text_.bidi.vis2log(vpos); double const old_tmpx = tmpx; if (body_pos > 0 && pos == body_pos - 1) { - LyXLayout_ptr const & layout = pars_[pit_].layout(); + LyXLayout_ptr const & layout = par_.layout(); LyXFont const lfont = getLabelFont(); tmpx += label_hfill_ + font_metrics::width(layout->labelsep, lfont); - if (pars_[pit_].isLineSeparator(body_pos - 1)) + if (par_.isLineSeparator(body_pos - 1)) tmpx -= singleWidth(body_pos - 1); } tmpx += singleWidth(pos); - if (hfillExpansion(pars_[pit_], row_, pos)) { + if (hfillExpansion(par_, row_, pos)) { if (pos >= body_pos) tmpx += hfill_; else tmpx += label_hfill_; } else { - if (pars_[pit_].isSeparator(pos) && pos >= body_pos) + if (par_.isSeparator(pos) && pos >= body_pos) tmpx += separator_; } @@ -494,7 +495,7 @@ void RowPainter::paintChangeBar() pos_type const start = row_.pos(); pos_type const end = row_.endpos(); - if (start == end || !pars_[pit_].isChanged(start, end - 1)) + if (start == end || !par_.isChanged(start, end - 1)) return; int const height = text_.isLastRow(pit_, row_) @@ -507,12 +508,12 @@ void RowPainter::paintChangeBar() void RowPainter::paintAppendix() { - if (!pars_[pit_].params().appendix()) + if (!par_.params().appendix()) return; int y = yo_; - if (pars_[pit_].params().startOfAppendix()) + if (par_.params().startOfAppendix()) y += 2 * defaultRowHeight(); pain_.line(1, y, 1, yo_ + row_.height(), LColor::appendix); @@ -522,7 +523,7 @@ void RowPainter::paintAppendix() void RowPainter::paintDepthBar() { - Paragraph::depth_type const depth = pars_[pit_].getDepth(); + Paragraph::depth_type const depth = par_.getDepth(); if (depth <= 0) return; @@ -588,7 +589,7 @@ int RowPainter::paintAppendixStart(int y) void RowPainter::paintFirst() { - ParagraphParameters const & parparams = pars_[pit_].params(); + ParagraphParameters const & parparams = par_.params(); int y_top = 0; @@ -598,12 +599,12 @@ void RowPainter::paintFirst() Buffer const & buffer = *bv_.buffer(); - LyXLayout_ptr const & layout = pars_[pit_].layout(); + LyXLayout_ptr const & layout = par_.layout(); if (buffer.params().paragraph_separation == BufferParams::PARSEP_SKIP) { if (pit_ != 0) { if (layout->latextype == LATEX_PARAGRAPH - && !pars_[pit_].getDepth()) { + && !par_.getDepth()) { y_top += buffer.params().getDefSkip().inPixels(bv_); } else { LyXLayout_ptr const & playout = pars_[pit_ - 1].layout(); @@ -616,9 +617,9 @@ void RowPainter::paintFirst() } } - bool const is_rtl = text_.isRTL(pars_[pit_]); + bool const is_rtl = text_.isRTL(par_); bool const is_seq = isFirstInSequence(pit_, text_.paragraphs()); - //lyxerr << "paintFirst: " << pars_[pit_].id() << " is_seq: " << is_seq << std::endl; + //lyxerr << "paintFirst: " << par_.id() << " is_seq: " << is_seq << std::endl; // should we print a label? if (layout->labeltype >= LABEL_STATIC @@ -627,9 +628,9 @@ void RowPainter::paintFirst() || is_seq)) { LyXFont font = getLabelFont(); - if (!pars_[pit_].getLabelstring().empty()) { + if (!par_.getLabelstring().empty()) { double x = x_; - string const str = pars_[pit_].getLabelstring(); + string const str = par_.getLabelstring(); // this is special code for the chapter layout. This is // printed in an extra row and has a pagebreak at @@ -677,8 +678,8 @@ void RowPainter::paintFirst() layout->labeltype == LABEL_BIBLIO || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)) { LyXFont font = getLabelFont(); - if (!pars_[pit_].getLabelstring().empty()) { - string const str = pars_[pit_].getLabelstring(); + if (!par_.getLabelstring().empty()) { + string const str = par_.getLabelstring(); float spacing_val = 1.0; if (!parparams.spacing().isDefault()) { spacing_val = parparams.spacing().getValue(); @@ -693,7 +694,7 @@ void RowPainter::paintFirst() double x = x_; if (layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) { x = ((is_rtl ? leftMargin() : x_) - + width_ - text_.rightMargin(pars_[pit_])) / 2; + + width_ - text_.rightMargin(par_)) / 2; x -= font_metrics::width(str, font) / 2; } else if (is_rtl) { x = width_ - leftMargin() - @@ -709,7 +710,7 @@ void RowPainter::paintFirst() void RowPainter::paintLast() { - bool const is_rtl = text_.isRTL(pars_[pit_]); + bool const is_rtl = text_.isRTL(par_); int const endlabel = getEndLabel(pit_, text_.paragraphs()); // draw an endlabel @@ -733,10 +734,10 @@ void RowPainter::paintLast() case END_LABEL_STATIC: { LyXFont font = getLabelFont(); - string const & str = pars_[pit_].layout()->endlabelstring(); + string const & str = par_.layout()->endlabelstring(); double const x = is_rtl ? x_ - font_metrics::width(str, font) - : - text_.rightMargin(pars_[pit_]) - row_.width(); + : - text_.rightMargin(par_) - row_.width(); pain_.text(int(x), yo_ + row_.baseline(), str, font); break; } @@ -750,13 +751,13 @@ void RowPainter::paintLast() void RowPainter::paintText() { pos_type const end = row_.endpos(); - pos_type body_pos = pars_[pit_].beginOfBody(); + pos_type body_pos = par_.beginOfBody(); if (body_pos > 0 && - (body_pos > end || !pars_[pit_].isLineSeparator(body_pos - 1))) { + (body_pos > end || !par_.isLineSeparator(body_pos - 1))) { body_pos = 0; } - LyXLayout_ptr const & layout = pars_[pit_].layout(); + LyXLayout_ptr const & layout = par_.layout(); bool running_strikeout = false; bool is_struckout = false; @@ -768,7 +769,7 @@ void RowPainter::paintText() pos_type pos = text_.bidi.vis2log(vpos); - if (pos >= pars_[pit_].size()) { + if (pos >= par_.size()) { ++vpos; continue; } @@ -779,15 +780,15 @@ void RowPainter::paintText() continue; } - is_struckout = isDeletedText(pars_[pit_], pos); + is_struckout = isDeletedText(par_, pos); if (is_struckout && !running_strikeout) { running_strikeout = true; last_strikeout_x = int(x_); } - bool const highly_editable_inset = pars_[pit_].isInset(pos) - && isHighlyEditableInset(pars_[pit_].getInset(pos)); + bool const highly_editable_inset = par_.isInset(pos) + && isHighlyEditableInset(par_.getInset(pos)); // if we reach the end of a struck out range, paint it // we also don't paint across things like tables @@ -805,7 +806,7 @@ void RowPainter::paintText() x_ += label_hfill_ + lwidth - singleWidth(body_pos - 1); } - if (pars_[pit_].isHfill(pos)) { + if (par_.isHfill(pos)) { x_ += 1; int const y0 = yo_ + row_.baseline(); @@ -813,7 +814,7 @@ void RowPainter::paintText() pain_.line(int(x_), y1, int(x_), y0, LColor::added_space); - if (hfillExpansion(pars_[pit_], row_, pos)) { + if (hfillExpansion(par_, row_, pos)) { int const y2 = (y0 + y1) / 2; if (pos >= body_pos) { @@ -831,7 +832,7 @@ void RowPainter::paintText() } x_ += 2; ++vpos; - } else if (pars_[pit_].isSeparator(pos)) { + } else if (par_.isSeparator(pos)) { x_ += singleWidth(pos); if (pos >= body_pos) x_ += separator_; diff --git a/src/text.C b/src/text.C index 20c889266b..853ddfa29d 100644 --- a/src/text.C +++ b/src/text.C @@ -439,17 +439,15 @@ int LyXText::height() const } -int LyXText::singleWidth(par_type par, pos_type pos) const +int LyXText::singleWidth(Paragraph const & par, pos_type pos) const { - char const c = pars_[par].getChar(pos); - return singleWidth(par, pos, c, getFont(par, pos)); + return singleWidth(par, pos, par.getChar(pos), getFont(par, pos)); } -int LyXText::singleWidth(par_type const pit, +int LyXText::singleWidth(Paragraph const & par, pos_type pos, char c, LyXFont const & font) const { - Paragraph const & par = pars_[pit]; if (pos >= par.size()) { lyxerr << "in singleWidth(), pos: " << pos << endl; BOOST_ASSERT(false); @@ -520,7 +518,7 @@ int LyXText::leftMargin(par_type const pit, pos_type const pos) const } } - LyXFont const labelfont = getLabelFont(pit); + LyXFont const labelfont = getLabelFont(par); switch (layout->margintype) { case MARGIN_DYNAMIC: if (!layout->leftmargin.empty()) @@ -730,13 +728,13 @@ void LyXText::rowBreakPoint(par_type const pit, Row & row) const char const c = par.getChar(i); { - int thiswidth = singleWidth(pit, i, c, *fi); + int thiswidth = singleWidth(par, i, c, *fi); // add the auto-hfill from label end to the body if (body_pos && i == body_pos) { - int add = font_metrics::width(layout->labelsep, getLabelFont(pit)); - if (pars_[pit].isLineSeparator(i - 1)) - add -= singleWidth(pit, i - 1); + int add = font_metrics::width(layout->labelsep, getLabelFont(par)); + if (par.isLineSeparator(i - 1)) + add -= singleWidth(par, i - 1); add = std::max(add, labelEnd(pit) - x); thiswidth += add; @@ -818,20 +816,20 @@ void LyXText::setRowWidth(par_type const pit, Row & row) const FontIterator fi = FontIterator(*this, pit, i); for ( ; i < end; ++i, ++fi) { if (body_pos > 0 && i == body_pos) { - w += font_metrics::width(labelsep, getLabelFont(pit)); + w += font_metrics::width(labelsep, getLabelFont(par)); if (par.isLineSeparator(i - 1)) - w -= singleWidth(pit, i - 1); + w -= singleWidth(par, i - 1); w = max(w, labelEnd(pit)); } char const c = par.getChar(i); - w += singleWidth(pit, i, c, *fi); + w += singleWidth(par, i, c, *fi); } } if (body_pos > 0 && body_pos >= end) { - w += font_metrics::width(labelsep, getLabelFont(pit)); + w += font_metrics::width(labelsep, getLabelFont(par)); if (end > 0 && par.isLineSeparator(end - 1)) - w -= singleWidth(pit, end - 1); + w -= singleWidth(par, end - 1); w = max(w, labelEnd(pit)); } @@ -840,9 +838,9 @@ void LyXText::setRowWidth(par_type const pit, Row & row) const // returns the minimum space a manual label needs on the screen in pixel -int LyXText::labelFill(par_type pit, Row const & row) const +int LyXText::labelFill(Paragraph const & par, Row const & row) const { - pos_type last = pars_[pit].beginOfBody(); + pos_type last = par.beginOfBody(); BOOST_ASSERT(last > 0); @@ -850,18 +848,18 @@ int LyXText::labelFill(par_type pit, Row const & row) const --last; // a separator at this end does not count - if (pars_[pit].isLineSeparator(last)) + if (par.isLineSeparator(last)) --last; int w = 0; for (pos_type i = row.pos(); i <= last; ++i) - w += singleWidth(pit, i); + w += singleWidth(par, i); - string const & label = pars_[pit].params().labelWidthString(); + string const & label = par.params().labelWidthString(); if (label.empty()) return 0; - return max(0, font_metrics::width(label, getLabelFont(pit)) - w); + return max(0, font_metrics::width(label, getLabelFont(par)) - w); } @@ -871,8 +869,9 @@ LColor_color LyXText::backgroundColor() const } -void LyXText::setHeightOfRow(par_type pit, Row & row) +void LyXText::setHeightOfRow(par_type const pit, Row & row) { + Paragraph const & par = pars_[pit]; // get the maximum ascent and the maximum descent double layoutasc = 0; double layoutdesc = 0; @@ -881,30 +880,29 @@ void LyXText::setHeightOfRow(par_type pit, Row & row) // ok, let us initialize the maxasc and maxdesc value. // Only the fontsize count. The other properties // are taken from the layoutfont. Nicer on the screen :) - LyXLayout_ptr const & layout = pars_[pit].layout(); + LyXLayout_ptr const & layout = par.layout(); // as max get the first character of this row then it can // increase but not decrease the height. Just some point to // start with so we don't have to do the assignment below too // often. - LyXFont font = getFont(pit, row.pos()); + LyXFont font = getFont(par, row.pos()); LyXFont::FONT_SIZE const tmpsize = font.size(); font = getLayoutFont(pit); LyXFont::FONT_SIZE const size = font.size(); font.setSize(tmpsize); - LyXFont labelfont = getLabelFont(pit); + LyXFont labelfont = getLabelFont(par); // these are minimum values - double const spacing_val = - layout->spacing.getValue() * spacing(pars_[pit]); + double const spacing_val = layout->spacing.getValue() * spacing(par); //lyxerr << "spacing_val = " << spacing_val << endl; int maxasc = int(font_metrics::maxAscent(font) * spacing_val); int maxdesc = int(font_metrics::maxDescent(font) * spacing_val); // insets may be taller - InsetList::const_iterator ii = pars_[pit].insetlist.begin(); - InsetList::const_iterator iend = pars_[pit].insetlist.end(); + InsetList::const_iterator ii = par.insetlist.begin(); + InsetList::const_iterator iend = par.insetlist.end(); for ( ; ii != iend; ++ii) { if (ii->pos >= row.pos() && ii->pos < row.endpos()) { maxasc = max(maxasc, ii->inset->ascent()); @@ -919,7 +917,7 @@ void LyXText::setHeightOfRow(par_type pit, Row & row) pos_type const pos_end = row.endpos(); LyXFont::FONT_SIZE maxsize = - pars_[pit].highestFontInRange(row.pos(), pos_end, size); + par.highestFontInRange(row.pos(), pos_end, size); if (maxsize > font.size()) { font.setSize(maxsize); maxasc = max(maxasc, font_metrics::maxAscent(font)); @@ -939,7 +937,7 @@ void LyXText::setHeightOfRow(par_type pit, Row & row) if (bv()->buffer()->params().paragraph_separation == BufferParams::PARSEP_SKIP && pit != 0 - && ((layout->isParagraph() && pars_[pit].getDepth() == 0) + && ((layout->isParagraph() && par.getDepth() == 0) || (pars_[pit - 1].layout()->isParagraph() && pars_[pit - 1].getDepth() == 0))) { @@ -954,7 +952,7 @@ void LyXText::setHeightOfRow(par_type pit, Row & row) if (layout->counter == "chapter" && bufparams.secnumdepth >= 0) { labeladdon = int(font_metrics::maxHeight(labelfont) * layout->spacing.getValue() - * spacing(pars_[pit])); + * spacing(par)); } // special code for the top label @@ -962,12 +960,12 @@ void LyXText::setHeightOfRow(par_type pit, Row & row) || layout->labeltype == LABEL_BIBLIO || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) && isFirstInSequence(pit, paragraphs()) - && !pars_[pit].getLabelstring().empty()) + && !par.getLabelstring().empty()) { labeladdon = int( font_metrics::maxHeight(labelfont) * layout->spacing.getValue() - * spacing(pars_[pit]) + * spacing(par) + (layout->topsep + layout->labelbottomsep) * dh); } @@ -975,11 +973,11 @@ void LyXText::setHeightOfRow(par_type pit, Row & row) // a section, or between the items of a itemize or enumerate // environment. - par_type prev = depthHook(pit, pars_, pars_[pit].getDepth()); + par_type prev = depthHook(pit, pars_, par.getDepth()); if (prev != pit && pars_[prev].layout() == layout - && pars_[prev].getDepth() == pars_[pit].getDepth() - && pars_[prev].getLabelWidthString() == pars_[pit].getLabelWidthString()) + && pars_[prev].getDepth() == par.getDepth() + && pars_[prev].getLabelWidthString() == par.getLabelWidthString()) { layoutasc = layout->itemsep * dh; } else if (pit != 0 || row.pos() != 0) { @@ -999,7 +997,7 @@ void LyXText::setHeightOfRow(par_type pit, Row & row) } // is it a bottom line? - if (row.endpos() >= pars_[pit].size()) { + if (row.endpos() >= par.size()) { // add the layout spaces, for example before and after // a section, or between the items of a itemize or enumerate // environment @@ -1036,6 +1034,10 @@ void LyXText::setHeightOfRow(par_type pit, Row & row) } +namespace { + +} + void LyXText::breakParagraph(LCursor & cur, char keep_layout) { BOOST_ASSERT(this == cur.text()); @@ -1083,7 +1085,7 @@ void LyXText::breakParagraph(LCursor & cur, char keep_layout) // well this is the caption hack since one caption is really enough if (layout->labeltype == LABEL_SENSITIVE) { - if (!cur.pos()) + if (cur.pos() == 0) // set to standard-layout pars_[cpit].applyLayout(tclass.defaultLayout()); else @@ -1138,7 +1140,7 @@ void LyXText::insertChar(LCursor & cur, char c) Paragraph & par = cur.paragraph(); // try to remove this - par_type pit = cur.par(); + par_type const pit = cur.par(); bool const freeSpacing = par.layout()->free_spacing || par.isFreeSpacing(); @@ -1153,8 +1155,8 @@ void LyXText::insertChar(LCursor & cur, char c) !(contains(number_seperators, c) && cur.pos() != 0 && cur.pos() != cur.lastpos() && - getFont(pit, cur.pos()).number() == LyXFont::ON && - getFont(pit, cur.pos() - 1).number() == LyXFont::ON) + getFont(par, cur.pos()).number() == LyXFont::ON && + getFont(par, cur.pos() - 1).number() == LyXFont::ON) ) number(cur); // Set current_font.number to OFF } else if (IsDigit(c) && @@ -1171,7 +1173,7 @@ void LyXText::insertChar(LCursor & cur, char c) setCharFont(pit, cur.pos() - 1, current_font); } else if (contains(number_seperators, c) && cur.pos() >= 2 - && getFont(pit, cur.pos() - 2).number() == LyXFont::ON) { + && getFont(par, cur.pos() - 2).number() == LyXFont::ON) { setCharFont(pit, cur.pos() - 1, current_font); } } @@ -1243,40 +1245,41 @@ void LyXText::charInserted() } -RowMetrics LyXText::computeRowMetrics(par_type pit, Row const & row) const +RowMetrics LyXText::computeRowMetrics(par_type const pit, Row const & row) const { RowMetrics result; + Paragraph const & par = pars_[pit]; double w = width_ - row.width(); - bool const is_rtl = isRTL(pars_[pit]); + bool const is_rtl = isRTL(par); if (is_rtl) - result.x = rightMargin(pars_[pit]); + result.x = rightMargin(par); else result.x = leftMargin(pit, row.pos()); // is there a manual margin with a manual label - LyXLayout_ptr const & layout = pars_[pit].layout(); + LyXLayout_ptr const & layout = par.layout(); if (layout->margintype == MARGIN_MANUAL && layout->labeltype == LABEL_MANUAL) { /// We might have real hfills in the label part - int nlh = numberOfLabelHfills(pars_[pit], row); + int nlh = numberOfLabelHfills(par, row); // A manual label par (e.g. List) has an auto-hfill // between the label text and the body of the // paragraph too. // But we don't want to do this auto hfill if the par // is empty. - if (!pars_[pit].empty()) + if (!par.empty()) ++nlh; - if (nlh && !pars_[pit].getLabelWidthString().empty()) - result.label_hfill = labelFill(pit, row) / double(nlh); + if (nlh && !par.getLabelWidthString().empty()) + result.label_hfill = labelFill(par, row) / double(nlh); } // are there any hfills in the row? - int const nh = numberOfHfills(pars_[pit], row); + int const nh = numberOfHfills(par, row); if (nh) { if (w > 0) @@ -1288,28 +1291,28 @@ RowMetrics LyXText::computeRowMetrics(par_type pit, Row const & row) const // is it block, flushleft or flushright? // set x how you need it int align; - if (pars_[pit].params().align() == LYX_ALIGN_LAYOUT) + if (par.params().align() == LYX_ALIGN_LAYOUT) align = layout->align; else - align = pars_[pit].params().align(); + align = par.params().align(); // Display-style insets should always be on a centred row - // The test on pars_[pit].size() is to catch zero-size pars, which + // The test on par.size() is to catch zero-size pars, which // would trigger the assert in Paragraph::getInset(). - //inset = pars_[pit].size() ? pars_[pit].getInset(row.pos()) : 0; - if (!pars_[pit].empty() - && pars_[pit].isInset(row.pos()) - && pars_[pit].getInset(row.pos())->display()) + //inset = par.size() ? par.getInset(row.pos()) : 0; + if (!par.empty() + && par.isInset(row.pos()) + && par.getInset(row.pos())->display()) { align = LYX_ALIGN_CENTER; } switch (align) { case LYX_ALIGN_BLOCK: { - int const ns = numberOfSeparators(pars_[pit], row); + int const ns = numberOfSeparators(par, row); bool disp_inset = false; - if (row.endpos() < pars_[pit].size()) { - InsetBase const * in = pars_[pit].getInset(row.endpos()); + if (row.endpos() < par.size()) { + InsetBase const * in = par.getInset(row.endpos()); if (in) disp_inset = in->display(); } @@ -1317,8 +1320,8 @@ RowMetrics LyXText::computeRowMetrics(par_type pit, Row const & row) const // par, does not end in newline, and is not row above a // display inset... then stretch it if (ns - && row.endpos() < pars_[pit].size() - && !pars_[pit].isNewline(row.endpos() - 1) + && row.endpos() < par.size() + && !par.isNewline(row.endpos() - 1) && !disp_inset ) { result.separator = w / ns; @@ -1336,15 +1339,15 @@ RowMetrics LyXText::computeRowMetrics(par_type pit, Row const & row) const } } - bidi.computeTables(pars_[pit], *bv()->buffer(), row); + bidi.computeTables(par, *bv()->buffer(), row); if (is_rtl) { - pos_type body_pos = pars_[pit].beginOfBody(); + pos_type body_pos = par.beginOfBody(); pos_type end = row.endpos(); if (body_pos > 0 - && (body_pos > end || !pars_[pit].isLineSeparator(body_pos - 1))) + && (body_pos > end || !par.isLineSeparator(body_pos - 1))) { - result.x += font_metrics::width(layout->labelsep, getLabelFont(pit)); + result.x += font_metrics::width(layout->labelsep, getLabelFont(par)); if (body_pos <= end) result.x += result.label_hfill; } @@ -1687,43 +1690,44 @@ Row const & LyXText::firstRow() const } -void LyXText::redoParagraphInternal(par_type pit) +void LyXText::redoParagraphInternal(par_type const pit) { // remove rows of paragraph, keep track of height changes - height_ -= pars_[pit].height; + Paragraph & par = pars_[pit]; + height_ -= par.height; // clear old data - pars_[pit].rows.clear(); - pars_[pit].height = 0; - pars_[pit].width = 0; + par.rows.clear(); + par.height = 0; + par.width = 0; // redo insets - InsetList::iterator ii = pars_[pit].insetlist.begin(); - InsetList::iterator iend = pars_[pit].insetlist.end(); + InsetList::iterator ii = par.insetlist.begin(); + InsetList::iterator iend = par.insetlist.end(); for (; ii != iend; ++ii) { Dimension dim; - int const w = maxwidth_ - leftMargin(pit) - rightMargin(pars_[pit]); - MetricsInfo mi(bv(), getFont(pit, ii->pos), w); + int const w = maxwidth_ - leftMargin(pit) - rightMargin(par); + MetricsInfo mi(bv(), getFont(par, ii->pos), w); ii->inset->metrics(mi, dim); } // rebreak the paragraph - pars_[pit].setBeginOfBody(); + par.setBeginOfBody(); pos_type z = 0; do { Row row(z); rowBreakPoint(pit, row); setRowWidth(pit, row); setHeightOfRow(pit, row); - row.y_offset(pars_[pit].height); - pars_[pit].rows.push_back(row); - pars_[pit].width = std::max(pars_[pit].width, row.width()); - pars_[pit].height += row.height(); + row.y_offset(par.height); + par.rows.push_back(row); + par.width = std::max(par.width, row.width()); + par.height += row.height(); z = row.endpos(); - } while (z < pars_[pit].size()); + } while (z < par.size()); - height_ += pars_[pit].height; - //lyxerr << "redoParagraph: " << pars_[pit].rows.size() << " rows\n"; + height_ += par.height; + //lyxerr << "redoParagraph: " << par.rows.size() << " rows\n"; } @@ -1919,11 +1923,12 @@ int LyXText::descent() const int LyXText::cursorX(CursorSlice const & cur) const { - par_type pit = cur.par(); - if (pars_[pit].rows.empty()) + par_type const pit = cur.par(); + Paragraph const & par = pars_[pit]; + if (par.rows.empty()) return xo_; - Row const & row = *pars_[pit].getRow(cur.pos()); + Row const & row = *par.getRow(cur.pos()); pos_type pos = cur.pos(); pos_type cursor_vpos = 0; @@ -1937,7 +1942,7 @@ int LyXText::cursorX(CursorSlice const & cur) const if (end <= row_pos) cursor_vpos = row_pos; else if (pos >= end) - cursor_vpos = isRTL(pars_[pit]) ? row_pos : end; + cursor_vpos = isRTL(par) ? row_pos : end; else if (pos > row_pos && pos >= end) // Place cursor after char at (logical) position pos - 1 cursor_vpos = (bidi.level(pos - 1) % 2 == 0) @@ -1947,33 +1952,33 @@ int LyXText::cursorX(CursorSlice const & cur) const cursor_vpos = (bidi.level(pos) % 2 == 0) ? bidi.log2vis(pos) : bidi.log2vis(pos) + 1; - pos_type body_pos = pars_[pit].beginOfBody(); + pos_type body_pos = par.beginOfBody(); if (body_pos > 0 && - (body_pos > end || !pars_[pit].isLineSeparator(body_pos - 1))) + (body_pos > end || !par.isLineSeparator(body_pos - 1))) body_pos = 0; for (pos_type vpos = row_pos; vpos < cursor_vpos; ++vpos) { pos_type pos = bidi.vis2log(vpos); if (body_pos > 0 && pos == body_pos - 1) { x += m.label_hfill - + font_metrics::width(pars_[pit].layout()->labelsep, - getLabelFont(pit)); - if (pars_[pit].isLineSeparator(body_pos - 1)) - x -= singleWidth(pit, body_pos - 1); + + font_metrics::width(par.layout()->labelsep, + getLabelFont(par)); + if (par.isLineSeparator(body_pos - 1)) + x -= singleWidth(par, body_pos - 1); } - if (hfillExpansion(pars_[pit], row, pos)) { - x += singleWidth(pit, pos); + if (hfillExpansion(par, row, pos)) { + x += singleWidth(par, pos); if (pos >= body_pos) x += m.hfill; else x += m.label_hfill; - } else if (pars_[pit].isSeparator(pos)) { - x += singleWidth(pit, pos); + } else if (par.isSeparator(pos)) { + x += singleWidth(par, pos); if (pos >= body_pos) x += m.separator; } else - x += singleWidth(pit, pos); + x += singleWidth(par, pos); } return xo_ + int(x); } diff --git a/src/text2.C b/src/text2.C index d871e2a826..69faa8486a 100644 --- a/src/text2.C +++ b/src/text2.C @@ -90,7 +90,7 @@ void LyXText::init(BufferView * bv) for (par_type pit = 0; pit != end; ++pit) pars_[pit].rows.clear(); - current_font = getFont(0, 0); + current_font = getFont(pars_[0], 0); redoParagraphs(0, end); updateCounters(); } @@ -149,11 +149,10 @@ InsetBase * LyXText::checkInsetHit(int x, int y) const // The difference is that this one is used for displaying, and thus we // are allowed to make cosmetic improvements. For instance make footnotes // smaller. (Asger) -LyXFont LyXText::getFont(par_type const pit, pos_type const pos) const +LyXFont LyXText::getFont(Paragraph const & par, pos_type const pos) const { BOOST_ASSERT(pos >= 0); - Paragraph const & par = pars_[pit]; LyXLayout_ptr const & layout = par.layout(); #ifdef WITH_WARNINGS #warning broken? @@ -186,7 +185,6 @@ LyXFont LyXText::getFont(par_type const pit, pos_type const pos) const font.realize(font_); // Realize with the fonts of lesser depth. - //font.realize(outerFont(pit, paragraphs())); font.realize(defaultfont_); return font; @@ -209,16 +207,15 @@ LyXFont LyXText::getLayoutFont(par_type const pit) const } -LyXFont LyXText::getLabelFont(par_type pit) const +LyXFont LyXText::getLabelFont(Paragraph const & par) const { - LyXLayout_ptr const & layout = pars_[pit].layout(); + LyXLayout_ptr const & layout = par.layout(); - if (!pars_[pit].getDepth()) + if (!par.getDepth()) return layout->reslabelfont; LyXFont font = layout->labelfont; // Realize with the fonts of lesser depth. - font.realize(outerFont(pit, paragraphs())); font.realize(defaultfont_); return font; @@ -436,7 +433,7 @@ void LyXText::setFont(LCursor & cur, LyXFont const & font, bool toggleall) LyXFont layoutfont; par_type pit = cur.par(); if (cur.pos() < pars_[pit].beginOfBody()) - layoutfont = getLabelFont(pit); + layoutfont = getLabelFont(pars_[pit]); else layoutfont = getLayoutFont(pit); @@ -460,21 +457,18 @@ void LyXText::setFont(LCursor & cur, LyXFont const & font, bool toggleall) par_type const beg = cur.selBegin().par(); par_type const end = cur.selEnd().par(); - DocIterator pos = cur.selectionBegin(); - DocIterator posend = cur.selectionEnd(); - - lyxerr[Debug::DEBUG] << "pos: " << pos << " posend: " << posend - << endl; + DocIterator dit = cur.selectionBegin(); + DocIterator ditend = cur.selectionEnd(); BufferParams const & params = cur.buffer().params(); - // Don't use forwardChar here as posend might have + // Don't use forwardChar here as ditend might have // pos() == lastpos() and forwardChar would miss it. - for (; pos != posend; pos.forwardPos()) { - if (pos.pos() != pos.lastpos()) { - LyXFont f = getFont(pos.par(), pos.pos()); + for (; dit != ditend; dit.forwardPos()) { + if (dit.pos() != dit.lastpos()) { + LyXFont f = getFont(dit.paragraph(), dit.pos()); f.update(font, params.language, toggleall); - setCharFont(pos.par(), pos.pos(), f); + setCharFont(dit.par(), dit.pos(), f); } } @@ -1028,7 +1022,7 @@ void LyXText::setCurrentFont(LCursor & cur) { BOOST_ASSERT(this == cur.text()); pos_type pos = cur.pos(); - par_type pit = cur.par(); + Paragraph & par = cur.paragraph(); if (cur.boundary() && pos > 0) --pos; @@ -1037,7 +1031,7 @@ void LyXText::setCurrentFont(LCursor & cur) if (pos == cur.lastpos()) --pos; else // potentional bug... BUG (Lgb) - if (pars_[pit].isSeparator(pos)) { + if (par.isSeparator(pos)) { if (pos > cur.textRow().pos() && bidi.level(pos) % 2 == bidi.level(pos - 1) % 2) @@ -1048,13 +1042,13 @@ void LyXText::setCurrentFont(LCursor & cur) } BufferParams const & bufparams = cur.buffer().params(); - current_font = pars_[pit].getFontSettings(bufparams, pos); - real_current_font = getFont(pit, pos); + current_font = par.getFontSettings(bufparams, pos); + real_current_font = getFont(par, pos); if (cur.pos() == cur.lastpos() - && bidi.isBoundary(cur.buffer(), pars_[pit], cur.pos()) + && bidi.isBoundary(cur.buffer(), par, cur.pos()) && !cur.boundary()) { - Language const * lang = pars_[pit].getParLanguage(bufparams); + Language const * lang = par.getParLanguage(bufparams); current_font.setLanguage(lang); current_font.setNumber(LyXFont::OFF); real_current_font.setLanguage(lang); @@ -1066,26 +1060,27 @@ void LyXText::setCurrentFont(LCursor & cur) // x is an absolute screen coord // returns the column near the specified x-coordinate of the row // x is set to the real beginning of this column -pos_type LyXText::getColumnNearX(par_type pit, +pos_type LyXText::getColumnNearX(par_type const pit, Row const & row, int & x, bool & boundary) const { x -= xo_; RowMetrics const r = computeRowMetrics(pit, row); + Paragraph const & par = pars_[pit]; pos_type vc = row.pos(); pos_type end = row.endpos(); pos_type c = 0; - LyXLayout_ptr const & layout = pars_[pit].layout(); + LyXLayout_ptr const & layout = par.layout(); bool left_side = false; - pos_type body_pos = pars_[pit].beginOfBody(); + pos_type body_pos = par.beginOfBody(); double tmpx = r.x; double last_tmpx = tmpx; if (body_pos > 0 && - (body_pos > end || !pars_[pit].isLineSeparator(body_pos - 1))) + (body_pos > end || !par.isLineSeparator(body_pos - 1))) body_pos = 0; // check for empty row @@ -1099,23 +1094,23 @@ pos_type LyXText::getColumnNearX(par_type pit, last_tmpx = tmpx; if (body_pos > 0 && c == body_pos - 1) { tmpx += r.label_hfill + - font_metrics::width(layout->labelsep, getLabelFont(pit)); - if (pars_[pit].isLineSeparator(body_pos - 1)) - tmpx -= singleWidth(pit, body_pos - 1); + font_metrics::width(layout->labelsep, getLabelFont(par)); + if (par.isLineSeparator(body_pos - 1)) + tmpx -= singleWidth(par, body_pos - 1); } - if (hfillExpansion(pars_[pit], row, c)) { - tmpx += singleWidth(pit, c); + if (hfillExpansion(par, row, c)) { + tmpx += singleWidth(par, c); if (c >= body_pos) tmpx += r.hfill; else tmpx += r.label_hfill; - } else if (pars_[pit].isSeparator(c)) { - tmpx += singleWidth(pit, c); + } else if (par.isSeparator(c)) { + tmpx += singleWidth(par, c); if (c >= body_pos) tmpx += r.separator; } else { - tmpx += singleWidth(pit, c); + tmpx += singleWidth(par, c); } ++vc; } @@ -1130,11 +1125,11 @@ pos_type LyXText::getColumnNearX(par_type pit, boundary = false; // This (rtl_support test) is not needed, but gives // some speedup if rtl_support == false - bool const lastrow = lyxrc.rtl_support && row.endpos() == pars_[pit].size(); + bool const lastrow = lyxrc.rtl_support && row.endpos() == par.size(); // If lastrow is false, we don't need to compute // the value of rtl. - bool const rtl = lastrow ? isRTL(pars_[pit]) : false; + bool const rtl = lastrow ? isRTL(par) : false; if (lastrow && ((rtl && left_side && vc == row.pos() && x < tmpx - 5) || (!rtl && !left_side && vc == end && x > tmpx + 5))) @@ -1148,15 +1143,15 @@ pos_type LyXText::getColumnNearX(par_type pit, bool const rtl = (bidi.level(c) % 2 == 1); if (left_side == rtl) { ++c; - boundary = bidi.isBoundary(*bv()->buffer(), pars_[pit], c); + boundary = bidi.isBoundary(*bv()->buffer(), par, c); } } - if (row.pos() < end && c >= end && pars_[pit].isNewline(end - 1)) { + if (row.pos() < end && c >= end && par.isNewline(end - 1)) { if (bidi.level(end -1) % 2 == 0) - tmpx -= singleWidth(pit, end - 1); + tmpx -= singleWidth(par, end - 1); else - tmpx += singleWidth(pit, end - 1); + tmpx += singleWidth(par, end - 1); c = end - 1; }