mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-26 19:25:39 +00:00
Merge the Row and RowMetrics class. Those classes were separated in the 1.4 code base because the Row list was part of Paragraph. As it is now in ParagraphMetrics, there is no need to separate them. Also, only compute the rowmetrics once when the containing paragraph is redone.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19858 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
598e5ecb9a
commit
be8de62ae2
@ -23,13 +23,8 @@
|
||||
namespace lyx {
|
||||
|
||||
|
||||
RowMetrics::RowMetrics()
|
||||
: separator(0), hfill(0), label_hfill(0), x(0)
|
||||
{}
|
||||
|
||||
|
||||
Row::Row()
|
||||
: pos_(0), end_(0)
|
||||
: pos_(0), end_(0), separator(0), hfill(0), label_hfill(0), x(0)
|
||||
{}
|
||||
|
||||
|
||||
|
24
src/Row.h
24
src/Row.h
@ -60,6 +60,15 @@ public:
|
||||
/// current debugging only
|
||||
void dump(const char * = "") const;
|
||||
|
||||
/// 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;
|
||||
|
||||
private:
|
||||
/// first pos covered by this row
|
||||
pos_type pos_;
|
||||
@ -70,21 +79,6 @@ private:
|
||||
};
|
||||
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace lyx
|
||||
|
||||
#endif
|
||||
|
10
src/Text.cpp
10
src/Text.cpp
@ -48,7 +48,6 @@
|
||||
#include "Paragraph.h"
|
||||
#include "paragraph_funcs.h"
|
||||
#include "ParagraphParameters.h"
|
||||
#include "rowpainter.h"
|
||||
#include "Undo.h"
|
||||
#include "VSpace.h"
|
||||
#include "WordLangTuple.h"
|
||||
@ -1656,8 +1655,7 @@ int Text::cursorX(BufferView const & bv, CursorSlice const & sl,
|
||||
pos_type cursor_vpos = 0;
|
||||
|
||||
Buffer const & buffer = bv.buffer();
|
||||
RowMetrics const m = tm.computeRowMetrics(pit, row);
|
||||
double x = m.x;
|
||||
double x = row.x;
|
||||
Bidi bidi;
|
||||
bidi.computeTables(par, buffer, row);
|
||||
|
||||
@ -1705,7 +1703,7 @@ int Text::cursorX(BufferView const & bv, CursorSlice const & sl,
|
||||
if (body_pos > 0 && pos == body_pos - 1) {
|
||||
FontMetrics const & labelfm = theFontMetrics(
|
||||
getLabelFont(buffer, par));
|
||||
x += m.label_hfill + labelfm.width(par.layout()->labelsep);
|
||||
x += row.label_hfill + labelfm.width(par.layout()->labelsep);
|
||||
if (par.isLineSeparator(body_pos - 1))
|
||||
x -= tm.singleWidth(pit, body_pos - 1);
|
||||
}
|
||||
@ -1719,9 +1717,9 @@ int Text::cursorX(BufferView const & bv, CursorSlice const & sl,
|
||||
x += pm.singleWidth(pos, font);
|
||||
|
||||
if (par.hfillExpansion(row, pos))
|
||||
x += (pos >= body_pos) ? m.hfill : m.label_hfill;
|
||||
x += (pos >= body_pos) ? row.hfill : row.label_hfill;
|
||||
else if (par.isSeparator(pos) && pos >= body_pos)
|
||||
x += m.separator;
|
||||
x += row.separator;
|
||||
}
|
||||
|
||||
// see correction above
|
||||
|
@ -39,7 +39,6 @@ class Color_color;
|
||||
class Cursor;
|
||||
class PainterInfo;
|
||||
class Row;
|
||||
class RowMetrics;
|
||||
class Spacing;
|
||||
|
||||
|
||||
|
@ -242,6 +242,7 @@ bool TextMetrics::redoParagraph(pit_type const pit)
|
||||
rowBreakPoint(width, pit, row);
|
||||
setRowWidth(right_margin, pit, row);
|
||||
setHeightOfRow(pit, row);
|
||||
computeRowMetrics(pit, row);
|
||||
pm.rows().push_back(row);
|
||||
pm.dim().wid = std::max(pm.dim().wid, row.width());
|
||||
pm.dim().des += row.height();
|
||||
@ -255,6 +256,7 @@ bool TextMetrics::redoParagraph(pit_type const pit)
|
||||
row.endpos(z);
|
||||
setRowWidth(right_margin, pit, row);
|
||||
setHeightOfRow(pit, row);
|
||||
computeRowMetrics(pit, row);
|
||||
pm.rows().push_back(row);
|
||||
pm.dim().des += row.height();
|
||||
}
|
||||
@ -271,10 +273,9 @@ bool TextMetrics::redoParagraph(pit_type const pit)
|
||||
return changed;
|
||||
}
|
||||
|
||||
RowMetrics TextMetrics::computeRowMetrics(pit_type const pit,
|
||||
Row const & row) const
|
||||
void TextMetrics::computeRowMetrics(pit_type const pit,
|
||||
Row & row) const
|
||||
{
|
||||
RowMetrics result;
|
||||
Buffer & buffer = bv_->buffer();
|
||||
Paragraph const & par = text_->getPar(pit);
|
||||
|
||||
@ -282,9 +283,9 @@ RowMetrics TextMetrics::computeRowMetrics(pit_type const pit,
|
||||
|
||||
bool const is_rtl = text_->isRTL(buffer, par);
|
||||
if (is_rtl)
|
||||
result.x = rightMargin(pit);
|
||||
row.x = rightMargin(pit);
|
||||
else
|
||||
result.x = text_->leftMargin(buffer, max_width_, pit, row.pos());
|
||||
row.x = text_->leftMargin(buffer, max_width_, pit, row.pos());
|
||||
|
||||
// is there a manual margin with a manual label
|
||||
LayoutPtr const & layout = par.layout();
|
||||
@ -303,7 +304,7 @@ RowMetrics TextMetrics::computeRowMetrics(pit_type const pit,
|
||||
++nlh;
|
||||
|
||||
if (nlh && !par.getLabelWidthString().empty())
|
||||
result.label_hfill = labelFill(pit, row) / double(nlh);
|
||||
row.label_hfill = labelFill(pit, row) / double(nlh);
|
||||
}
|
||||
|
||||
// are there any hfills in the row?
|
||||
@ -311,7 +312,7 @@ RowMetrics TextMetrics::computeRowMetrics(pit_type const pit,
|
||||
|
||||
if (nh) {
|
||||
if (w > 0)
|
||||
result.hfill = w / nh;
|
||||
row.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!
|
||||
@ -362,17 +363,17 @@ RowMetrics TextMetrics::computeRowMetrics(pit_type const pit,
|
||||
&& !par.isNewline(row.endpos() - 1)
|
||||
&& !disp_inset
|
||||
) {
|
||||
result.separator = w / ns;
|
||||
row.separator = w / ns;
|
||||
} else if (is_rtl) {
|
||||
result.x += w;
|
||||
row.x += w;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case LYX_ALIGN_RIGHT:
|
||||
result.x += w;
|
||||
row.x += w;
|
||||
break;
|
||||
case LYX_ALIGN_CENTER:
|
||||
result.x += w / 2;
|
||||
row.x += w / 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -384,14 +385,12 @@ RowMetrics TextMetrics::computeRowMetrics(pit_type const pit,
|
||||
if (body_pos > 0
|
||||
&& (body_pos > end || !par.isLineSeparator(body_pos - 1)))
|
||||
{
|
||||
result.x += theFontMetrics(text_->getLabelFont(buffer, par)).
|
||||
row.x += theFontMetrics(text_->getLabelFont(buffer, par)).
|
||||
width(layout->labelsep);
|
||||
if (body_pos <= end)
|
||||
result.x += result.label_hfill;
|
||||
row.x += row.label_hfill;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@ -815,7 +814,6 @@ pos_type TextMetrics::getColumnNearX(pit_type const pit,
|
||||
/// x Paragraph coordinate is always 0 for main text anyway.
|
||||
int const xo = main_text_? 0 : bv_->coordCache().get(text_, pit).x_;
|
||||
x -= xo;
|
||||
RowMetrics const r = computeRowMetrics(pit, row);
|
||||
Paragraph const & par = text_->getPar(pit);
|
||||
Bidi bidi;
|
||||
bidi.computeTables(par, buffer, row);
|
||||
@ -829,7 +827,7 @@ pos_type TextMetrics::getColumnNearX(pit_type const pit,
|
||||
|
||||
pos_type body_pos = par.beginOfBody();
|
||||
|
||||
double tmpx = r.x;
|
||||
double tmpx = row.x;
|
||||
double last_tmpx = tmpx;
|
||||
|
||||
if (body_pos > 0 &&
|
||||
@ -848,7 +846,7 @@ pos_type TextMetrics::getColumnNearX(pit_type const pit,
|
||||
if (body_pos > 0 && c == body_pos - 1) {
|
||||
FontMetrics const & fm = theFontMetrics(
|
||||
text_->getLabelFont(buffer, par));
|
||||
tmpx += r.label_hfill + fm.width(layout->labelsep);
|
||||
tmpx += row.label_hfill + fm.width(layout->labelsep);
|
||||
if (par.isLineSeparator(body_pos - 1))
|
||||
tmpx -= singleWidth(pit, body_pos - 1);
|
||||
}
|
||||
@ -856,13 +854,13 @@ pos_type TextMetrics::getColumnNearX(pit_type const pit,
|
||||
if (par.hfillExpansion(row, c)) {
|
||||
tmpx += singleWidth(pit, c);
|
||||
if (c >= body_pos)
|
||||
tmpx += r.hfill;
|
||||
tmpx += row.hfill;
|
||||
else
|
||||
tmpx += r.label_hfill;
|
||||
tmpx += row.label_hfill;
|
||||
} else if (par.isSeparator(c)) {
|
||||
tmpx += singleWidth(pit, c);
|
||||
if (c >= body_pos)
|
||||
tmpx += r.separator;
|
||||
tmpx += row.separator;
|
||||
} else {
|
||||
tmpx += singleWidth(pit, c);
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ public:
|
||||
|
||||
/** this calculates the specified parameters. needed when setting
|
||||
* the cursor and when creating a visible row */
|
||||
RowMetrics computeRowMetrics(pit_type pit, Row const & row) const;
|
||||
void computeRowMetrics(pit_type pit, Row & row) const;
|
||||
|
||||
///
|
||||
void draw(PainterInfo & pi, int x, int y) const;
|
||||
|
@ -63,17 +63,12 @@ RowPainter::RowPainter(PainterInfo & pi,
|
||||
bidi_(bidi), erased_(pi.erased_),
|
||||
xo_(x), yo_(y), width_(text_metrics_.width())
|
||||
{
|
||||
RowMetrics m = text_metrics_.computeRowMetrics(pit_, row_);
|
||||
bidi_.computeTables(par_, bv_.buffer(), row_);
|
||||
x_ = m.x + xo_;
|
||||
x_ = row_.x + xo_;
|
||||
|
||||
//lyxerr << "RowPainter: x: " << x_ << " xo: " << xo_ << " yo: " << yo_ << endl;
|
||||
//row_.dump();
|
||||
|
||||
separator_ = m.separator;
|
||||
hfill_ = m.hfill;
|
||||
label_hfill_ = m.label_hfill;
|
||||
|
||||
BOOST_ASSERT(pit >= 0);
|
||||
BOOST_ASSERT(pit < int(text.paragraphs().size()));
|
||||
}
|
||||
@ -731,7 +726,7 @@ void RowPainter::paintText()
|
||||
int const lwidth = theFontMetrics(getLabelFont())
|
||||
.width(layout->labelsep);
|
||||
|
||||
x_ += label_hfill_ + lwidth - width_pos;
|
||||
x_ += row_.label_hfill + lwidth - width_pos;
|
||||
}
|
||||
|
||||
if (par_.isHfill(pos)) {
|
||||
@ -746,15 +741,15 @@ void RowPainter::paintText()
|
||||
int const y2 = (y0 + y1) / 2;
|
||||
|
||||
if (pos >= body_pos) {
|
||||
pain_.line(int(x_), y2, int(x_ + hfill_), y2,
|
||||
pain_.line(int(x_), y2, int(x_ + row_.hfill), y2,
|
||||
Color::added_space,
|
||||
Painter::line_onoffdash);
|
||||
x_ += hfill_;
|
||||
x_ += row_.hfill;
|
||||
} else {
|
||||
pain_.line(int(x_), y2, int(x_ + label_hfill_), y2,
|
||||
pain_.line(int(x_), y2, int(x_ + row_.label_hfill), y2,
|
||||
Color::added_space,
|
||||
Painter::line_onoffdash);
|
||||
x_ += label_hfill_;
|
||||
x_ += row_.label_hfill;
|
||||
}
|
||||
pain_.line(int(x_), y1, int(x_), y0, Color::added_space);
|
||||
}
|
||||
@ -765,7 +760,7 @@ void RowPainter::paintText()
|
||||
double const orig_x = x_;
|
||||
x_ += width_pos;
|
||||
if (pos >= body_pos)
|
||||
x_ += separator_;
|
||||
x_ += row_.separator;
|
||||
++vpos;
|
||||
paintForeignMark(orig_x, orig_font);
|
||||
} else {
|
||||
|
@ -99,9 +99,6 @@ private:
|
||||
int const yo_; // current baseline
|
||||
double x_;
|
||||
int width_;
|
||||
double separator_;
|
||||
double hfill_;
|
||||
double label_hfill_;
|
||||
};
|
||||
|
||||
} // namespace lyx
|
||||
|
Loading…
Reference in New Issue
Block a user