From dd306473146eec6098bf9c15ae23107658379360 Mon Sep 17 00:00:00 2001 From: Alfredo Braunstein Date: Mon, 1 Mar 2004 12:23:17 +0000 Subject: [PATCH] move prepareToPrint out of the rowbreaking loop, do not cache its results. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8468 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Bidi.C | 2 +- src/Bidi.h | 2 +- src/ChangeLog | 13 ++++++++++ src/lyxrow.C | 58 +++++--------------------------------------- src/lyxrow.h | 40 +++++++++++++------------------ src/lyxtext.h | 5 ++-- src/rowpainter.C | 12 +++++----- src/text.C | 62 +++++++++++++++++++++++------------------------- src/text2.C | 19 +++++++-------- 9 files changed, 85 insertions(+), 128 deletions(-) diff --git a/src/Bidi.C b/src/Bidi.C index 86a6f8defc..ce9b4651d5 100644 --- a/src/Bidi.C +++ b/src/Bidi.C @@ -52,7 +52,7 @@ bool Bidi::same_direction() const void Bidi::computeTables(Paragraph const & par, - Buffer const & buf, Row & row) + Buffer const & buf, Row const & row) { same_direction_ = true; if (!lyxrc.rtl_support) { diff --git a/src/Bidi.h b/src/Bidi.h index a616090877..d556bc8944 100644 --- a/src/Bidi.h +++ b/src/Bidi.h @@ -45,7 +45,7 @@ struct Bidi { bool same_direction() const; /// void computeTables(Paragraph const & par, - Buffer const &, Row & row); + Buffer const &, Row const & row); private: /// bool same_direction_; diff --git a/src/ChangeLog b/src/ChangeLog index 86d503d67a..3ea318b02c 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,16 @@ + +2004-03-01 Alfredo Braunstein + + * Bidi.[Ch] (computeTables): const correctness + * lyxrow.[Ch]: add RowMetrics class, move there fill_separator, + fill_hfill, fill_label_hfill and x from Row + * lyxtext.h: prepareToPrint returns a RowMetrics + * rowPainter.C: adjust + * text.C (prepareToPrint): use width, not textWidth. adjust + (redoParagraphInternal, cursorX): adjust + * text2.C (getColumnNearX): adjust + (init): put a default value to the top LyXText::width + 2004-03-01 Alfredo Braunstein * FontIterator.[Ch]: move FontIterator from lyxtext.h/text.C to here diff --git a/src/lyxrow.C b/src/lyxrow.C index bf4d0a6b40..901de6dd2b 100644 --- a/src/lyxrow.C +++ b/src/lyxrow.C @@ -22,17 +22,19 @@ using lyx::pos_type; +RowMetrics::RowMetrics() : separator(0), hfill(0), label_hfill(0), x(0) +{} + + Row::Row() : pos_(0), end_(0), height_(0), width_(0), y_offset_(0), - ascent_of_text_(0), baseline_(0), - x_(0), fill_separator_(0), fill_hfill_(0), fill_label_hfill_(0) + ascent_of_text_(0), baseline_(0) {} Row::Row(pos_type pos) : pos_(pos), end_(0), height_(0), width_(0), y_offset_(0), - ascent_of_text_(0), baseline_(0), - x_(0), fill_separator_(0), fill_hfill_(0), fill_label_hfill_(0) + ascent_of_text_(0), baseline_(0) {} @@ -108,54 +110,6 @@ unsigned int Row::baseline() const } -float Row::x() const -{ - return x_; -} - - -void Row::x(float f) -{ - x_ = f; -} - - -float Row::fill_separator() const -{ - return fill_separator_; -} - - -void Row::fill_separator(float f) -{ - fill_separator_ = f; -} - - -float Row::fill_hfill() const -{ - return fill_hfill_; -} - - -void Row::fill_hfill(float f) -{ - fill_hfill_ = f; -} - - -float Row::fill_label_hfill() const -{ - return fill_label_hfill_; -} - - -void Row::fill_label_hfill(float f) -{ - fill_label_hfill_ = f; -} - - bool Row::isParStart() const { return !pos(); diff --git a/src/lyxrow.h b/src/lyxrow.h index c17e634933..d855d77e30 100644 --- a/src/lyxrow.h +++ b/src/lyxrow.h @@ -58,24 +58,9 @@ public: unsigned int y_offset() const { return y_offset_; } /// cache the y position void y_offset(unsigned int newy) { y_offset_ = newy; } - /// - float x() const; - /// - void x(float); - /// - float fill_separator() const; - /// - void fill_separator(float); - /// - float fill_hfill() const; - /// - void fill_hfill(float); - /// - float fill_label_hfill() const; - /// - void fill_label_hfill(float); /// current debugging only void dump(const char * = "") const; + private: /// first pos covered by this row lyx::pos_type pos_; @@ -93,14 +78,21 @@ private: unsigned int top_of_text_; /// unsigned int baseline_; - /// offet from left border - float x_; - /// - float fill_separator_; - /// - float fill_hfill_; - /// - float fill_label_hfill_; }; + +class RowMetrics { +public: + RowMetrics(); + /// width of a separator (i.e. space) + double separator; + /// width of hfills in the body + double hfill; + /// width of hfills in the label + double label_hfill; + /// the x position of the row + double x; +}; + + #endif diff --git a/src/lyxtext.h b/src/lyxtext.h index 3ab56aeb9c..865c78865b 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -41,11 +41,11 @@ class MetricsInfo; class PainterInfo; class Paragraph; class Row; +class RowMetrics; class Spacing; class UpdatableInset; class VSpace; - /// This class encapsulates the main text data and operations in LyX class LyXText { public: @@ -320,7 +320,8 @@ public: /** this calculates the specified parameters. needed when setting * the cursor and when creating a visible row */ - void prepareToPrint(ParagraphList::iterator pit, Row & row) const; + RowMetrics + prepareToPrint(ParagraphList::iterator pit, Row const & row) const; /// access to our paragraphs ParagraphList & paragraphs() const; diff --git a/src/rowpainter.C b/src/rowpainter.C index 0fcb40cab9..03a48bdd6d 100644 --- a/src/rowpainter.C +++ b/src/rowpainter.C @@ -120,16 +120,16 @@ RowPainter::RowPainter(BufferView const & bv, LyXText const & text, ParagraphList::iterator pit, RowList::iterator rit, int xo, int yo) : bv_(bv), pain_(bv_.painter()), text_(text), rit_(rit), row_(*rit), - pit_(pit), xo_(xo), yo_(yo), x_(row_.x()), - width_(text_.textWidth()), - separator_(row_.fill_separator()), - hfill_(row_.fill_hfill()), - label_hfill_(row_.fill_label_hfill()) + pit_(pit), xo_(xo), yo_(yo), width_(text_.width) { //lyxerr << "RowPainter: x: " << x_ << " xo: " << xo << " yo: " << yo // << " pit->y: " << pit_->y // << " row: " << (pit_->size() ? pit_->getChar(row_.pos()) : 'X') << endl; - x_ += xo_; + RowMetrics m = text_.prepareToPrint(pit, row_); + x_ = m.x + xo_; + separator_ = m.separator; + hfill_ = m.hfill; + label_hfill_ = m.label_hfill; // background has already been cleared. if (&text_ == bv_.text()) diff --git a/src/text.C b/src/text.C index fcb390712d..055ebc9364 100644 --- a/src/text.C +++ b/src/text.C @@ -368,6 +368,7 @@ int LyXText::leftMargin(ParagraphList::iterator pit, pos_type pos) const break; } } + if (!pit->params().leftIndent().zero()) x += pit->params().leftIndent().inPixels(textWidth()); @@ -1005,19 +1006,18 @@ void LyXText::charInserted() } -void LyXText::prepareToPrint(ParagraphList::iterator pit, Row & row) const +RowMetrics +LyXText::prepareToPrint(ParagraphList::iterator pit, Row const & row) const { - double w = textWidth() - row.width(); - double fill_hfill = 0; - double fill_label_hfill = 0; - double fill_separator = 0; - double x = 0; + RowMetrics result; + + double w = width - row.width(); bool const is_rtl = isRTL(*pit); if (is_rtl) - x = rightMargin(*pit); + result.x = rightMargin(*pit); else - x = leftMargin(pit, row.pos()); + result.x = leftMargin(pit, row.pos()); // is there a manual margin with a manual label LyXLayout_ptr const & layout = pit->layout(); @@ -1036,7 +1036,7 @@ void LyXText::prepareToPrint(ParagraphList::iterator pit, Row & row) const ++nlh; if (nlh && !pit->getLabelWidthString().empty()) - fill_label_hfill = labelFill(pit, row) / double(nlh); + result.label_hfill = labelFill(pit, row) / double(nlh); } // are there any hfills in the row? @@ -1044,7 +1044,7 @@ void LyXText::prepareToPrint(ParagraphList::iterator pit, Row & row) const if (nh) { if (w > 0) - fill_hfill = w / nh; + result.hfill = w / nh; // we don't have to look at the alignment if it is ALIGN_LEFT and // if the row is already larger then the permitted width as then // we force the LEFT_ALIGN'edness! @@ -1085,17 +1085,17 @@ void LyXText::prepareToPrint(ParagraphList::iterator pit, Row & row) const && !pit->isNewline(row.endpos() - 1) && !disp_inset ) { - fill_separator = w / ns; + result.separator = w / ns; } else if (is_rtl) { - x += w; + result.x += w; } break; } case LYX_ALIGN_RIGHT: - x += w; + result.x += w; break; case LYX_ALIGN_CENTER: - x += w / 2; + result.x += w / 2; break; } } @@ -1108,16 +1108,13 @@ void LyXText::prepareToPrint(ParagraphList::iterator pit, Row & row) const if (body_pos > 0 && (body_pos > end || !pit->isLineSeparator(body_pos - 1))) { - x += font_metrics::width(layout->labelsep, getLabelFont(pit)); + result.x += font_metrics::width(layout->labelsep, getLabelFont(pit)); if (body_pos <= end) - x += fill_label_hfill; + result.x += result.label_hfill; } } - row.fill_hfill(fill_hfill); - row.fill_label_hfill(fill_label_hfill); - row.fill_separator(fill_separator); - row.x(x); + return result; } @@ -1578,7 +1575,6 @@ void LyXText::redoParagraphInternal(ParagraphList::iterator pit) Row row(z); rowBreakPoint(pit, row); setRowWidth(pit, row); - prepareToPrint(pit, row); setHeightOfRow(pit, row); row.y_offset(pit->height); pit->rows.push_back(row); @@ -1817,13 +1813,15 @@ int LyXText::cursorX(CursorSlice const & cur) const ParagraphList::iterator pit = getPar(cur); if (pit->rows.empty()) return xo_; - Row const & row = *pit->getRow(cur.pos()); - pos_type pos = cur.pos(); - pos_type cursor_vpos = 0; - double x = row.x(); - double fill_separator = row.fill_separator(); - double fill_hfill = row.fill_hfill(); - double fill_label_hfill = row.fill_label_hfill(); + Row const & row = *pit->getRow(cur.pos()); + + + pos_type pos = cur.pos(); + pos_type cursor_vpos = 0; + + RowMetrics const m = prepareToPrint(pit, row); + double x = m.x; + pos_type const row_pos = row.pos(); pos_type const end = row.endpos(); @@ -1848,7 +1846,7 @@ int LyXText::cursorX(CursorSlice const & cur) const 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 += fill_label_hfill + x += m.label_hfill + font_metrics::width(pit->layout()->labelsep, getLabelFont(pit)); if (pit->isLineSeparator(body_pos - 1)) @@ -1858,13 +1856,13 @@ int LyXText::cursorX(CursorSlice const & cur) const if (hfillExpansion(*pit, row, pos)) { x += singleWidth(pit, pos); if (pos >= body_pos) - x += fill_hfill; + x += m.hfill; else - x += fill_label_hfill; + x += m.label_hfill; } else if (pit->isSeparator(pos)) { x += singleWidth(pit, pos); if (pos >= body_pos) - x += fill_separator; + x += m.separator; } else x += singleWidth(pit, pos); } diff --git a/src/text2.C b/src/text2.C index 0a46ae2e63..aed16a2e63 100644 --- a/src/text2.C +++ b/src/text2.C @@ -87,7 +87,7 @@ void LyXText::init(BufferView * bv) for (ParagraphList::iterator pit = beg; pit != end; ++pit) pit->rows.clear(); - width = 0; + width = bv->workWidth(); height = 0; current_font = getFont(beg, 0); @@ -1197,11 +1197,8 @@ pos_type LyXText::getColumnNearX(ParagraphList::iterator pit, Row const & row, int & x, bool & boundary) const { x -= xo_; - double tmpx = row.x(); - double fill_separator = row.fill_separator(); - double fill_hfill = row.fill_hfill(); - double fill_label_hfill = row.fill_label_hfill(); - + RowMetrics const r = prepareToPrint(pit, row); + pos_type vc = row.pos(); pos_type end = row.endpos(); pos_type c = 0; @@ -1210,6 +1207,8 @@ pos_type LyXText::getColumnNearX(ParagraphList::iterator pit, bool left_side = false; pos_type body_pos = pit->beginOfBody(); + + double tmpx = r.x; double last_tmpx = tmpx; if (body_pos > 0 && @@ -1226,7 +1225,7 @@ pos_type LyXText::getColumnNearX(ParagraphList::iterator pit, c = bidi.vis2log(vc); last_tmpx = tmpx; if (body_pos > 0 && c == body_pos - 1) { - tmpx += fill_label_hfill + + tmpx += r.label_hfill + font_metrics::width(layout->labelsep, getLabelFont(pit)); if (pit->isLineSeparator(body_pos - 1)) tmpx -= singleWidth(pit, body_pos - 1); @@ -1235,13 +1234,13 @@ pos_type LyXText::getColumnNearX(ParagraphList::iterator pit, if (hfillExpansion(*pit, row, c)) { tmpx += singleWidth(pit, c); if (c >= body_pos) - tmpx += fill_hfill; + tmpx += r.hfill; else - tmpx += fill_label_hfill; + tmpx += r.label_hfill; } else if (pit->isSeparator(c)) { tmpx += singleWidth(pit, c); if (c >= body_pos) - tmpx += fill_separator; + tmpx += r.separator; } else { tmpx += singleWidth(pit, c); } -- 2.39.2