Cleanup Hfill metrics and painting. InsetHFill is now treated almost like any other inset.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21980 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2007-12-05 22:25:07 +00:00
parent 7a517b9461
commit 55a9524e99
5 changed files with 57 additions and 58 deletions

View File

@ -512,7 +512,6 @@ bool TextMetrics::redoParagraph(pit_type const pit)
void TextMetrics::computeRowMetrics(pit_type const pit,
Row & row, int width) const
{
row.label_hfill = 0;
row.hfill = 0;
row.separator = 0;
@ -638,6 +637,28 @@ void TextMetrics::computeRowMetrics(pit_type const pit,
row.x += row.label_hfill;
}
}
pos_type const endpos = row.endpos();
pos_type body_pos = par.beginOfBody();
if (body_pos > 0
&& (body_pos > endpos || !par.isLineSeparator(body_pos - 1)))
body_pos = 0;
ParagraphMetrics & pm = par_metrics_[pit];
InsetList::const_iterator ii = par.insetList().begin();
InsetList::const_iterator iend = par.insetList().end();
for ( ; ii != iend; ++ii) {
if (ii->pos >= endpos || ii->pos < row.pos()
|| ii->inset->lyxCode() != HFILL_CODE
|| !pm.hfillExpansion(row, ii->pos))
continue;
Dimension dim = row.dimension();
dim.wid = int(ii->pos >= body_pos ? row.hfill : row.label_hfill);
// Cache the inset dimension.
bv_->coordCache().insets().add(ii->inset, dim);
pm.setInsetDimension(ii->inset, dim);
}
}
@ -1045,7 +1066,6 @@ pos_type TextMetrics::getColumnNearX(pit_type const pit,
int const xo = origin_.x_;
x -= xo;
Paragraph const & par = text_->getPar(pit);
ParagraphMetrics const & pm = par_metrics_[pit];
Bidi bidi;
bidi.computeTables(par, buffer, row);
@ -1082,19 +1102,9 @@ pos_type TextMetrics::getColumnNearX(pit_type const pit,
tmpx -= singleWidth(pit, body_pos - 1);
}
if (pm.hfillExpansion(row, c)) {
tmpx += singleWidth(pit, c);
if (c >= body_pos)
tmpx += row.hfill;
else
tmpx += row.label_hfill;
} else if (par.isSeparator(c)) {
tmpx += singleWidth(pit, c);
if (c >= body_pos)
tmpx += singleWidth(pit, c);
if (par.isSeparator(c) && c >= body_pos)
tmpx += row.separator;
} else {
tmpx += singleWidth(pit, c);
}
++vc;
}
@ -1512,9 +1522,7 @@ int TextMetrics::cursorX(CursorSlice const & sl,
x += pm.singleWidth(pos, font);
if (pm.hfillExpansion(row, pos))
x += (pos >= body_pos) ? row.hfill : row.label_hfill;
else if (par.isSeparator(pos) && pos >= body_pos)
if (par.isSeparator(pos) && pos >= body_pos)
x += row.separator;
}

View File

@ -11,6 +11,11 @@
#include <config.h>
#include "InsetHFill.h"
#include "MetricsInfo.h"
#include "frontends/Painter.h"
#include "support/gettext.h"
#include <ostream>
@ -40,9 +45,30 @@ Inset * InsetHFill::clone() const
void InsetHFill::metrics(MetricsInfo &, Dimension & dim) const
{
dim.wid = 3;
dim.asc = 3;
dim.des = 3;
// The metrics for this inset are calculated externally in
// \c TextMetrics::computeRowMetrics. Those are dummy value:
dim = Dimension(10, 10, 10);
}
void InsetHFill::draw(PainterInfo & pi, int x, int y) const
{
Dimension const dim = Inset::dimension(*pi.base.bv);
x += 1;
int const y0 = y + dim.des;
int const y1 = y - dim.asc;
pi.pain.line(x, y1, x, y0, Color_added_space);
if (dim.wid == 0)
// The HFill is not expanded.
return;
int const x1 = x + dim.wid;
pi.pain.line(x, y, x1, y, Color_added_space,
frontend::Painter::line_onoffdash);
pi.pain.line(x1, y1, x1, y0, Color_added_space);
}

View File

@ -25,6 +25,8 @@ public:
///
void metrics(MetricsInfo &, Dimension &) const;
///
void draw(PainterInfo & pi, int x, int y) const;
///
docstring const getScreenLabel(Buffer const &) const;
///
InsetCode lyxCode() const { return HFILL_CODE; }

View File

@ -89,36 +89,6 @@ int RowPainter::leftMargin() const
row_.pos());
}
void RowPainter::paintHfill(pos_type const pos, pos_type const body_pos)
{
x_ += 1;
int const y0 = yo_;
int const y1 = y0 - defaultRowHeight() / 2;
pi_.pain.line(int(x_), y1, int(x_), y0, Color_added_space);
if (pm_.hfillExpansion(row_, pos)) {
int const y2 = (y0 + y1) / 2;
if (pos >= body_pos) {
pi_.pain.line(int(x_), y2, int(x_ + row_.hfill), y2,
Color_added_space,
Painter::line_onoffdash);
x_ += row_.hfill;
} else {
pi_.pain.line(int(x_), y2, int(x_ + row_.label_hfill), y2,
Color_added_space,
Painter::line_onoffdash);
x_ += row_.label_hfill;
}
pi_.pain.line(int(x_), y1, int(x_), y0, Color_added_space);
}
x_ += 2;
}
// If you want to debug inset metrics uncomment the following line:
//#define DEBUG_METRICS
// This draws green lines around each inset.
@ -774,13 +744,7 @@ void RowPainter::paintText()
x_ += row_.label_hfill + lwidth - width_pos;
}
if (par_.isHfill(pos)) {
Inset const * inset = par_.getInset(pos);
pi_.base.bv->coordCache().insets().add(inset, int(x_), yo_);
paintHfill(pos, body_pos);
++vpos;
} else if (par_.isSeparator(pos)) {
if (par_.isSeparator(pos)) {
Font const orig_font = text_metrics_.getDisplayFont(pit_, pos);
double const orig_x = x_;
x_ += width_pos;

View File

@ -63,7 +63,6 @@ private:
int paintAppendixStart(int y);
void paintFromPos(pos_type & vpos);
void paintInset(Inset const * inset, pos_type const pos);
void paintHfill(pos_type const pos, pos_type const body_pos);
/// return left margin
int leftMargin() const;