- Transfer rowpainter.cpp:paintPar() to TextMetrics::drawParagraph()

- move RowPainter class out of the anonymous namespace so that it can be used by TextMetrics::drawParagraph().


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19848 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2007-08-28 08:57:13 +00:00
parent a398211e03
commit 971c543b34
5 changed files with 180 additions and 176 deletions

View File

@ -1548,15 +1548,17 @@ void BufferView::draw(frontend::Painter & pain)
pain.fillRectangle(0, metrics_info_.y1, width_,
metrics_info_.y2 - metrics_info_.y1, text.backgroundColor());
TextMetrics const & tm = text_metrics_[&text];
if (select)
text.drawSelection(pi, 0, 0);
int yy = metrics_info_.y1;
// draw contents
for (pit_type pit = metrics_info_.p1; pit <= metrics_info_.p2; ++pit) {
ParagraphMetrics const & pm = parMetrics(&text, pit);
ParagraphMetrics const & pm = tm.parMetrics(pit);
yy += pm.ascent();
paintPar(pi, text, pit, 0, yy, repaintAll);
tm.drawParagraph(pi, pit, 0, yy, repaintAll);
yy += pm.descent();
}

View File

@ -973,11 +973,100 @@ void TextMetrics::draw(PainterInfo & pi, int x, int y) const
for (; it != end; ++it) {
ParagraphMetrics const & pmi = it->second;
y += pmi.ascent();
paintPar(pi, *text_, it->first, x, y, true);
drawParagraph(pi, it->first, x, y, true);
y += pmi.descent();
}
}
namespace {
bool CursorOnRow(PainterInfo & pi, pit_type const pit,
RowList::const_iterator rit, Text const & text)
{
// Is there a cursor on this row (or inside inset on row)
Cursor & cur = pi.base.bv->cursor();
for (size_type d = 0; d < cur.depth(); ++d) {
CursorSlice const & sl = cur[d];
if (sl.text() == &text
&& sl.pit() == pit
&& sl.pos() >= rit->pos()
&& sl.pos() <= rit->endpos())
return true;
}
return false;
}
} // namespace anon
void TextMetrics::drawParagraph(PainterInfo & pi, pit_type pit, int x, int y,
bool repaintAll) const
{
// lyxerr << " paintPar: pit: " << pit << " at y: " << y << endl;
int const ww = bv_->workHeight();
bv_->coordCache().parPos()[text_][pit] = Point(x, y);
ParagraphMetrics const & pm = par_metrics_[pit];
if (pm.rows().empty())
return;
RowList::const_iterator const rb = pm.rows().begin();
RowList::const_iterator const re = pm.rows().end();
Bidi bidi;
y -= rb->ascent();
size_type rowno = 0;
for (RowList::const_iterator rit = rb; rit != re; ++rit, ++rowno) {
y += rit->ascent();
// Row signature; has row changed since last paint?
bool row_has_changed = pm.rowChangeStatus()[rowno];
bool cursor_on_row = CursorOnRow(pi, pit, rit, *text_);
// If selection is on, the current row signature differs
// from cache, or cursor is inside an inset _on this row_,
// then paint the row
if (repaintAll || row_has_changed || cursor_on_row) {
bool const inside = (y + rit->descent() >= 0
&& y - rit->ascent() < ww);
// it is not needed to draw on screen if we are not inside.
pi.pain.setDrawingEnabled(inside);
RowPainter rp(pi, *text_, pit, *rit, bidi, x, y);
// Clear background of this row
// (if paragraph background was not cleared)
if (!repaintAll && row_has_changed)
pi.pain.fillRectangle(x, y - rit->ascent(),
width(), rit->height(),
text_->backgroundColor());
// Instrumentation for testing row cache (see also
// 12 lines lower):
if (lyxerr.debugging(Debug::PAINTING)) {
if (text_->isMainText(bv_->buffer()))
LYXERR(Debug::PAINTING) << "#";
else
LYXERR(Debug::PAINTING) << "[" <<
repaintAll << row_has_changed <<
cursor_on_row << "]";
}
rp.paintAppendix();
rp.paintDepthBar();
rp.paintChangeBar();
if (rit == rb)
rp.paintFirst();
rp.paintText();
if (rit + 1 == re)
rp.paintLast();
}
y += rit->descent();
}
// Re-enable screen drawing for future use of the painter.
pi.pain.setDrawingEnabled(true);
LYXERR(Debug::PAINTING) << "." << endl;
}
//int Text::pos2x(pit_type pit, pos_type pos) const
//{

View File

@ -73,7 +73,11 @@ public:
* the cursor and when creating a visible row */
RowMetrics computeRowMetrics(pit_type pit, Row const & row) const;
///
void draw(PainterInfo & pi, int x, int y) const;
void drawParagraph(PainterInfo & pi, pit_type pit, int x, int y,
bool repaintAll) const;
private:
///

View File

@ -43,89 +43,15 @@
#include <boost/crc.hpp>
namespace lyx {
using frontend::Painter;
using frontend::FontMetrics;
using std::endl;
using std::max;
using std::string;
namespace {
/**
* A class used for painting an individual row of text.
*/
class RowPainter {
public:
/// initialise and run painter
RowPainter(PainterInfo & pi, Text const & text,
pit_type pit, Row const & row, Bidi & bidi, int x, int y);
// paint various parts
void paintAppendix();
void paintDepthBar();
void paintChangeBar();
void paintFirst();
void paintLast();
void paintText();
private:
void paintForeignMark(double orig_x, Font const & font, int desc = 0);
void paintHebrewComposeChar(pos_type & vpos, Font const & font);
void paintArabicComposeChar(pos_type & vpos, Font const & font);
void paintChars(pos_type & vpos, Font const & font,
bool hebrew, bool arabic);
int paintAppendixStart(int y);
void paintFromPos(pos_type & vpos);
void paintInset(pos_type const pos, Font const & font);
/// return left margin
int leftMargin() const;
/// return the label font for this row
Font const getLabelFont() const;
/// bufferview to paint on
BufferView & bv_;
/// Painter to use
Painter & pain_;
/// Text for the row
Text const & text_;
TextMetrics & text_metrics_;
ParagraphList const & pars_;
/// The row to paint
Row const & row_;
/// Row's paragraph
pit_type const pit_;
Paragraph const & par_;
ParagraphMetrics const & pm_;
/// bidi cache, comes from outside the rowpainter because
/// rowpainters are normally created in a for loop and there only
/// one of them is active at a time.
Bidi & bidi_;
/// is row erased? (change tracking)
bool erased_;
// Looks ugly - is
double const xo_;
int const yo_; // current baseline
double x_;
int width_;
double separator_;
double hfill_;
double label_hfill_;
};
namespace lyx {
using frontend::Painter;
using frontend::FontMetrics;
RowPainter::RowPainter(PainterInfo & pi,
Text const & text, pit_type pit, Row const & row, Bidi & bidi, int x, int y)
@ -859,95 +785,4 @@ void RowPainter::paintText()
}
}
bool CursorOnRow(PainterInfo & pi, pit_type const pit,
RowList::const_iterator rit, Text const & text)
{
// Is there a cursor on this row (or inside inset on row)
Cursor & cur = pi.base.bv->cursor();
for (size_type d = 0; d < cur.depth(); ++d) {
CursorSlice const & sl = cur[d];
if (sl.text() == &text
&& sl.pit() == pit
&& sl.pos() >= rit->pos()
&& sl.pos() <= rit->endpos())
return true;
}
return false;
}
} // namespace anon
void paintPar
(PainterInfo & pi, Text const & text, pit_type pit, int x, int y,
bool repaintAll)
{
// lyxerr << " paintPar: pit: " << pit << " at y: " << y << endl;
int const ww = pi.base.bv->workHeight();
pi.base.bv->coordCache().parPos()[&text][pit] = Point(x, y);
TextMetrics const & tm = pi.base.bv->textMetrics(&text);
ParagraphMetrics const & pm = tm.parMetrics(pit);
if (pm.rows().empty())
return;
RowList::const_iterator const rb = pm.rows().begin();
RowList::const_iterator const re = pm.rows().end();
Bidi bidi;
y -= rb->ascent();
size_type rowno = 0;
for (RowList::const_iterator rit = rb; rit != re; ++rit, ++rowno) {
y += rit->ascent();
// Row signature; has row changed since last paint?
bool row_has_changed = pm.rowChangeStatus()[rowno];
bool cursor_on_row = CursorOnRow(pi, pit, rit, text);
// If selection is on, the current row signature differs
// from cache, or cursor is inside an inset _on this row_,
// then paint the row
if (repaintAll || row_has_changed || cursor_on_row) {
bool const inside = (y + rit->descent() >= 0
&& y - rit->ascent() < ww);
// it is not needed to draw on screen if we are not inside.
pi.pain.setDrawingEnabled(inside);
RowPainter rp(pi, text, pit, *rit, bidi, x, y);
// Clear background of this row
// (if paragraph background was not cleared)
if (!repaintAll && row_has_changed)
pi.pain.fillRectangle(x, y - rit->ascent(),
tm.width(), rit->height(),
text.backgroundColor());
// Instrumentation for testing row cache (see also
// 12 lines lower):
if (lyxerr.debugging(Debug::PAINTING)) {
if (text.isMainText(pi.base.bv->buffer()))
LYXERR(Debug::PAINTING) << "#";
else
LYXERR(Debug::PAINTING) << "[" <<
repaintAll << row_has_changed <<
cursor_on_row << "]";
}
rp.paintAppendix();
rp.paintDepthBar();
rp.paintChangeBar();
if (rit == rb)
rp.paintFirst();
rp.paintText();
if (rit + 1 == re)
rp.paintLast();
}
y += rit->descent();
}
// Re-enable screen drawing for future use of the painter.
pi.pain.setDrawingEnabled(true);
LYXERR(Debug::PAINTING) << "." << endl;
}
} // namespace lyx

View File

@ -18,17 +18,91 @@
namespace lyx {
class Text;
class Bidi;
class BufferView;
class Font;
class PainterInfo;
class Paragraph;
class ParagraphList;
class ParagraphMetrics;
class Row;
class Text;
class TextMetrics;
class ViewMetricsInfo;
namespace frontend { class Painter; }
/// paint paragraph.
void paintPar
(PainterInfo & pi, Text const & text, pit_type pit, int x, int y,
bool repaintAll);
/**
* A class used for painting an individual row of text.
* FIXME: get rid of that class.
*/
class RowPainter {
public:
/// initialise and run painter
RowPainter(PainterInfo & pi, Text const & text,
pit_type pit, Row const & row, Bidi & bidi, int x, int y);
/// paint various parts
/// FIXME: transfer to TextMetrics
void paintAppendix();
void paintDepthBar();
void paintChangeBar();
void paintFirst();
void paintLast();
void paintText();
private:
void paintForeignMark(double orig_x, Font const & font, int desc = 0);
void paintHebrewComposeChar(pos_type & vpos, Font const & font);
void paintArabicComposeChar(pos_type & vpos, Font const & font);
void paintChars(pos_type & vpos, Font const & font,
bool hebrew, bool arabic);
int paintAppendixStart(int y);
void paintFromPos(pos_type & vpos);
void paintInset(pos_type const pos, Font const & font);
/// return left margin
int leftMargin() const;
/// return the label font for this row
Font const getLabelFont() const;
/// bufferview to paint on
BufferView & bv_;
/// Painter to use
frontend::Painter & pain_;
/// Text for the row
Text const & text_;
TextMetrics & text_metrics_;
ParagraphList const & pars_;
/// The row to paint
Row const & row_;
/// Row's paragraph
pit_type const pit_;
Paragraph const & par_;
ParagraphMetrics const & pm_;
/// bidi cache, comes from outside the rowpainter because
/// rowpainters are normally created in a for loop and there only
/// one of them is active at a time.
Bidi & bidi_;
/// is row erased? (change tracking)
bool erased_;
// Looks ugly - is
double const xo_;
int const yo_; // current baseline
double x_;
int width_;
double separator_;
double hfill_;
double label_hfill_;
};
/// some space for drawing the 'nested' markers (in pixel)
inline int nestMargin() { return 15; }