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
This commit is contained in:
Alfredo Braunstein 2004-03-01 12:23:17 +00:00
parent a92a5e20e6
commit dd30647314
9 changed files with 85 additions and 128 deletions

View File

@ -52,7 +52,7 @@ bool Bidi::same_direction() const
void Bidi::computeTables(Paragraph const & par, void Bidi::computeTables(Paragraph const & par,
Buffer const & buf, Row & row) Buffer const & buf, Row const & row)
{ {
same_direction_ = true; same_direction_ = true;
if (!lyxrc.rtl_support) { if (!lyxrc.rtl_support) {

View File

@ -45,7 +45,7 @@ struct Bidi {
bool same_direction() const; bool same_direction() const;
/// ///
void computeTables(Paragraph const & par, void computeTables(Paragraph const & par,
Buffer const &, Row & row); Buffer const &, Row const & row);
private: private:
/// ///
bool same_direction_; bool same_direction_;

View File

@ -1,3 +1,16 @@
2004-03-01 Alfredo Braunstein <abraunst@lyx.org>
* 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 <abraunst@lyx.org> 2004-03-01 Alfredo Braunstein <abraunst@lyx.org>
* FontIterator.[Ch]: move FontIterator from lyxtext.h/text.C to here * FontIterator.[Ch]: move FontIterator from lyxtext.h/text.C to here

View File

@ -22,17 +22,19 @@
using lyx::pos_type; using lyx::pos_type;
RowMetrics::RowMetrics() : separator(0), hfill(0), label_hfill(0), x(0)
{}
Row::Row() Row::Row()
: pos_(0), end_(0), height_(0), width_(0), y_offset_(0), : pos_(0), end_(0), height_(0), width_(0), y_offset_(0),
ascent_of_text_(0), baseline_(0), ascent_of_text_(0), baseline_(0)
x_(0), fill_separator_(0), fill_hfill_(0), fill_label_hfill_(0)
{} {}
Row::Row(pos_type pos) Row::Row(pos_type pos)
: pos_(pos), end_(0), height_(0), width_(0), y_offset_(0), : pos_(pos), end_(0), height_(0), width_(0), y_offset_(0),
ascent_of_text_(0), baseline_(0), ascent_of_text_(0), baseline_(0)
x_(0), fill_separator_(0), fill_hfill_(0), fill_label_hfill_(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 bool Row::isParStart() const
{ {
return !pos(); return !pos();

View File

@ -58,24 +58,9 @@ public:
unsigned int y_offset() const { return y_offset_; } unsigned int y_offset() const { return y_offset_; }
/// cache the y position /// cache the y position
void y_offset(unsigned int newy) { y_offset_ = newy; } 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 /// current debugging only
void dump(const char * = "") const; void dump(const char * = "") const;
private: private:
/// first pos covered by this row /// first pos covered by this row
lyx::pos_type pos_; lyx::pos_type pos_;
@ -93,14 +78,21 @@ private:
unsigned int top_of_text_; unsigned int top_of_text_;
/// ///
unsigned int baseline_; 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 #endif

View File

@ -41,11 +41,11 @@ class MetricsInfo;
class PainterInfo; class PainterInfo;
class Paragraph; class Paragraph;
class Row; class Row;
class RowMetrics;
class Spacing; class Spacing;
class UpdatableInset; class UpdatableInset;
class VSpace; class VSpace;
/// This class encapsulates the main text data and operations in LyX /// This class encapsulates the main text data and operations in LyX
class LyXText { class LyXText {
public: public:
@ -320,7 +320,8 @@ public:
/** this calculates the specified parameters. needed when setting /** this calculates the specified parameters. needed when setting
* the cursor and when creating a visible row */ * 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 /// access to our paragraphs
ParagraphList & paragraphs() const; ParagraphList & paragraphs() const;

View File

@ -120,16 +120,16 @@ RowPainter::RowPainter(BufferView const & bv, LyXText const & text,
ParagraphList::iterator pit, RowList::iterator rit, ParagraphList::iterator pit, RowList::iterator rit,
int xo, int yo) int xo, int yo)
: bv_(bv), pain_(bv_.painter()), text_(text), rit_(rit), row_(*rit), : bv_(bv), pain_(bv_.painter()), text_(text), rit_(rit), row_(*rit),
pit_(pit), xo_(xo), yo_(yo), x_(row_.x()), pit_(pit), xo_(xo), yo_(yo), width_(text_.width)
width_(text_.textWidth()),
separator_(row_.fill_separator()),
hfill_(row_.fill_hfill()),
label_hfill_(row_.fill_label_hfill())
{ {
//lyxerr << "RowPainter: x: " << x_ << " xo: " << xo << " yo: " << yo //lyxerr << "RowPainter: x: " << x_ << " xo: " << xo << " yo: " << yo
// << " pit->y: " << pit_->y // << " pit->y: " << pit_->y
// << " row: " << (pit_->size() ? pit_->getChar(row_.pos()) : 'X') << endl; // << " 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. // background has already been cleared.
if (&text_ == bv_.text()) if (&text_ == bv_.text())

View File

@ -369,6 +369,7 @@ int LyXText::leftMargin(ParagraphList::iterator pit, pos_type pos) const
} }
} }
if (!pit->params().leftIndent().zero()) if (!pit->params().leftIndent().zero())
x += pit->params().leftIndent().inPixels(textWidth()); 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(); RowMetrics result;
double fill_hfill = 0;
double fill_label_hfill = 0; double w = width - row.width();
double fill_separator = 0;
double x = 0;
bool const is_rtl = isRTL(*pit); bool const is_rtl = isRTL(*pit);
if (is_rtl) if (is_rtl)
x = rightMargin(*pit); result.x = rightMargin(*pit);
else else
x = leftMargin(pit, row.pos()); result.x = leftMargin(pit, row.pos());
// is there a manual margin with a manual label // is there a manual margin with a manual label
LyXLayout_ptr const & layout = pit->layout(); LyXLayout_ptr const & layout = pit->layout();
@ -1036,7 +1036,7 @@ void LyXText::prepareToPrint(ParagraphList::iterator pit, Row & row) const
++nlh; ++nlh;
if (nlh && !pit->getLabelWidthString().empty()) 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? // are there any hfills in the row?
@ -1044,7 +1044,7 @@ void LyXText::prepareToPrint(ParagraphList::iterator pit, Row & row) const
if (nh) { if (nh) {
if (w > 0) 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 // 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 // if the row is already larger then the permitted width as then
// we force the LEFT_ALIGN'edness! // we force the LEFT_ALIGN'edness!
@ -1085,17 +1085,17 @@ void LyXText::prepareToPrint(ParagraphList::iterator pit, Row & row) const
&& !pit->isNewline(row.endpos() - 1) && !pit->isNewline(row.endpos() - 1)
&& !disp_inset && !disp_inset
) { ) {
fill_separator = w / ns; result.separator = w / ns;
} else if (is_rtl) { } else if (is_rtl) {
x += w; result.x += w;
} }
break; break;
} }
case LYX_ALIGN_RIGHT: case LYX_ALIGN_RIGHT:
x += w; result.x += w;
break; break;
case LYX_ALIGN_CENTER: case LYX_ALIGN_CENTER:
x += w / 2; result.x += w / 2;
break; break;
} }
} }
@ -1108,16 +1108,13 @@ void LyXText::prepareToPrint(ParagraphList::iterator pit, Row & row) const
if (body_pos > 0 if (body_pos > 0
&& (body_pos > end || !pit->isLineSeparator(body_pos - 1))) && (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) if (body_pos <= end)
x += fill_label_hfill; result.x += result.label_hfill;
} }
} }
row.fill_hfill(fill_hfill); return result;
row.fill_label_hfill(fill_label_hfill);
row.fill_separator(fill_separator);
row.x(x);
} }
@ -1578,7 +1575,6 @@ void LyXText::redoParagraphInternal(ParagraphList::iterator pit)
Row row(z); Row row(z);
rowBreakPoint(pit, row); rowBreakPoint(pit, row);
setRowWidth(pit, row); setRowWidth(pit, row);
prepareToPrint(pit, row);
setHeightOfRow(pit, row); setHeightOfRow(pit, row);
row.y_offset(pit->height); row.y_offset(pit->height);
pit->rows.push_back(row); pit->rows.push_back(row);
@ -1818,12 +1814,14 @@ int LyXText::cursorX(CursorSlice const & cur) const
if (pit->rows.empty()) if (pit->rows.empty())
return xo_; return xo_;
Row const & row = *pit->getRow(cur.pos()); Row const & row = *pit->getRow(cur.pos());
pos_type pos = cur.pos(); pos_type pos = cur.pos();
pos_type cursor_vpos = 0; pos_type cursor_vpos = 0;
double x = row.x();
double fill_separator = row.fill_separator(); RowMetrics const m = prepareToPrint(pit, row);
double fill_hfill = row.fill_hfill(); double x = m.x;
double fill_label_hfill = row.fill_label_hfill();
pos_type const row_pos = row.pos(); pos_type const row_pos = row.pos();
pos_type const end = row.endpos(); 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) { for (pos_type vpos = row_pos; vpos < cursor_vpos; ++vpos) {
pos_type pos = bidi.vis2log(vpos); pos_type pos = bidi.vis2log(vpos);
if (body_pos > 0 && pos == body_pos - 1) { if (body_pos > 0 && pos == body_pos - 1) {
x += fill_label_hfill x += m.label_hfill
+ font_metrics::width(pit->layout()->labelsep, + font_metrics::width(pit->layout()->labelsep,
getLabelFont(pit)); getLabelFont(pit));
if (pit->isLineSeparator(body_pos - 1)) if (pit->isLineSeparator(body_pos - 1))
@ -1858,13 +1856,13 @@ int LyXText::cursorX(CursorSlice const & cur) const
if (hfillExpansion(*pit, row, pos)) { if (hfillExpansion(*pit, row, pos)) {
x += singleWidth(pit, pos); x += singleWidth(pit, pos);
if (pos >= body_pos) if (pos >= body_pos)
x += fill_hfill; x += m.hfill;
else else
x += fill_label_hfill; x += m.label_hfill;
} else if (pit->isSeparator(pos)) { } else if (pit->isSeparator(pos)) {
x += singleWidth(pit, pos); x += singleWidth(pit, pos);
if (pos >= body_pos) if (pos >= body_pos)
x += fill_separator; x += m.separator;
} else } else
x += singleWidth(pit, pos); x += singleWidth(pit, pos);
} }

View File

@ -87,7 +87,7 @@ void LyXText::init(BufferView * bv)
for (ParagraphList::iterator pit = beg; pit != end; ++pit) for (ParagraphList::iterator pit = beg; pit != end; ++pit)
pit->rows.clear(); pit->rows.clear();
width = 0; width = bv->workWidth();
height = 0; height = 0;
current_font = getFont(beg, 0); current_font = getFont(beg, 0);
@ -1197,10 +1197,7 @@ pos_type LyXText::getColumnNearX(ParagraphList::iterator pit,
Row const & row, int & x, bool & boundary) const Row const & row, int & x, bool & boundary) const
{ {
x -= xo_; x -= xo_;
double tmpx = row.x(); RowMetrics const r = prepareToPrint(pit, row);
double fill_separator = row.fill_separator();
double fill_hfill = row.fill_hfill();
double fill_label_hfill = row.fill_label_hfill();
pos_type vc = row.pos(); pos_type vc = row.pos();
pos_type end = row.endpos(); pos_type end = row.endpos();
@ -1210,6 +1207,8 @@ pos_type LyXText::getColumnNearX(ParagraphList::iterator pit,
bool left_side = false; bool left_side = false;
pos_type body_pos = pit->beginOfBody(); pos_type body_pos = pit->beginOfBody();
double tmpx = r.x;
double last_tmpx = tmpx; double last_tmpx = tmpx;
if (body_pos > 0 && if (body_pos > 0 &&
@ -1226,7 +1225,7 @@ pos_type LyXText::getColumnNearX(ParagraphList::iterator pit,
c = bidi.vis2log(vc); c = bidi.vis2log(vc);
last_tmpx = tmpx; last_tmpx = tmpx;
if (body_pos > 0 && c == body_pos - 1) { if (body_pos > 0 && c == body_pos - 1) {
tmpx += fill_label_hfill + tmpx += r.label_hfill +
font_metrics::width(layout->labelsep, getLabelFont(pit)); font_metrics::width(layout->labelsep, getLabelFont(pit));
if (pit->isLineSeparator(body_pos - 1)) if (pit->isLineSeparator(body_pos - 1))
tmpx -= singleWidth(pit, 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)) { if (hfillExpansion(*pit, row, c)) {
tmpx += singleWidth(pit, c); tmpx += singleWidth(pit, c);
if (c >= body_pos) if (c >= body_pos)
tmpx += fill_hfill; tmpx += r.hfill;
else else
tmpx += fill_label_hfill; tmpx += r.label_hfill;
} else if (pit->isSeparator(c)) { } else if (pit->isSeparator(c)) {
tmpx += singleWidth(pit, c); tmpx += singleWidth(pit, c);
if (c >= body_pos) if (c >= body_pos)
tmpx += fill_separator; tmpx += r.separator;
} else { } else {
tmpx += singleWidth(pit, c); tmpx += singleWidth(pit, c);
} }