int RowPainter::singleWidth(lyx::pos_type pos) const
{
- BufferView * bv(perv(bv_));
Paragraph * par(const_cast<Paragraph*>(&par_));
- return text_.singleWidth(bv, par, pos);
+ return text_.singleWidth(par, pos);
}
int RowPainter::singleWidth(lyx::pos_type pos, char c) const
{
- BufferView * bv(perv(bv_));
Paragraph * par(const_cast<Paragraph*>(&par_));
- return text_.singleWidth(bv, par, pos, c);
+ return text_.singleWidth(par, pos, c);
}
int RowPainter::leftMargin() const
{
- BufferView * bv(perv(bv_));
Row * row(const_cast<Row *>(&row_));
- return text_.leftMargin(bv, row);
+ return text_.leftMargin(row);
}
-void RowPainter::paintNewline(pos_type const pos)
-{
- LyXFont const font = getFont(pos);
- int const wid = font_metrics::width('n', font);
- int const asc = font_metrics::maxAscent(font);
- int const y = yo_ + row_.baseline();
- // FIXME: rtl_pos, or ltr_pos ?
- bool const rtl_pos = (text_.bidi_level(pos) % 2 == 0);
- int xp[3];
- int yp[3];
-
- yp[0] = int(y - 0.875 * asc * 0.75);
- yp[1] = int(y - 0.500 * asc * 0.75);
- yp[2] = int(y - 0.125 * asc * 0.75);
-
- if (rtl_pos) {
- xp[0] = int(x_ + wid * 0.375);
- xp[1] = int(x_);
- xp[2] = int(x_ + wid * 0.375);
- } else {
- xp[0] = int(x_ + wid * 0.625);
- xp[1] = int(x_ + wid);
- xp[2] = int(x_ + wid * 0.625);
- }
-
- pain_.lines(xp, yp, 3, LColor::eolmarker);
-
- yp[0] = int(y - 0.500 * asc * 0.75);
- yp[1] = int(y - 0.500 * asc * 0.75);
- yp[2] = int(y - asc * 0.75);
-
- if (rtl_pos) {
- xp[0] = int(x_);
- xp[1] = int(x_ + wid);
- xp[2] = int(x_ + wid);
- } else {
- xp[0] = int(x_ + wid);
- xp[1] = int(x_);
- xp[2] = int(x_);
- }
-
- pain_.lines(xp, yp, 3, LColor::eolmarker);
-
- x_ += wid;
-}
-
-
-bool RowPainter::paintInset(pos_type const pos)
+void RowPainter::paintInset(pos_type const pos)
{
Inset * inset = const_cast<Inset*>(par_.getInset(pos));
LyXFont const & font = getFont(pos);
- inset->update(perv(bv_), font, false);
- inset->draw(perv(bv_), font, yo_ + row_.baseline(), x_, cleared_);
+#warning inset->update FIXME
+ inset->update(perv(bv_), false);
- // return true if something changed when we drew an inset
-
- return (!text_.need_break_row && !text_.isInInset()
- && bv_.text->status() == LyXText::CHANGED_IN_DRAW);
+ inset->draw(perv(bv_), font, yo_ + row_.baseline(), x_);
}
}
-bool RowPainter::paintFromPos(pos_type & vpos)
+void RowPainter::paintFromPos(pos_type & vpos)
{
pos_type const pos = text_.vis2log(vpos);
char const c = par_.getChar(pos);
- if (IsNewlineChar(c)) {
- ++vpos;
- paintNewline(pos);
- return true;
- } else if (IsInsetChar(c)) {
- if (paintInset(pos))
- return true;
+ if (IsInsetChar(c)) {
+ paintInset(pos);
++vpos;
paintForeignMark(orig_x, orig_font);
- return false;
+ return;
}
// usual characters, no insets
paintForeignMark(orig_x, orig_font);
- return false;
+ return;
}
-bool RowPainter::paintBackground()
+void RowPainter::paintBackground()
{
- pos_type const last = row_.lastPrintablePos();
- bool clear_area = true;
- Inset const * inset = 0;
-
- if (!bv_.screen().forceClear() && last == row_.pos()
- && par_.isInset(row_.pos())) {
- inset = par_.getInset(row_.pos());
- clear_area = inset->doClearArea();
- }
-
- if (cleared_) {
- return true;
- }
-
- if (clear_area) {
- int const x = xo_;
- int const y = yo_ < 0 ? 0 : yo_;
- int const h = yo_ < 0 ? row_.height() + yo_ : row_.height();
- pain_.fillRectangle(x, y, width_, h, text_.backgroundColor());
- return true;
- }
-
- if (!inset)
- return false;
-
- LyXFont font(LyXFont::ALL_SANE);
-
- // FIXME
- BufferView * bv = perv(bv_);
-
- int h = row_.baseline() - inset->ascent(bv, font);
-
- // first clear the whole row above the inset!
- if (h > 0) {
- pain_.fillRectangle(xo_, yo_, width_, h, text_.backgroundColor());
- }
-
- // clear the space below the inset!
- h += inset->ascent(bv, font) + inset->descent(bv, font);
- if ((row_.height() - h) > 0) {
- pain_.fillRectangle(xo_, yo_ + h,
- width_, row_.height() - h, text_.backgroundColor());
- }
-
- // clear the space behind the inset, if needed
- if (!inset->display() && !inset->needFullRow()) {
- int const xp = int(x_) + inset->width(bv, font);
- if (width_ - xp > 0) {
- pain_.fillRectangle(xp, yo_, width_ - xp,
- row_.height(), text_.backgroundColor());
- }
- }
-
- return false;
+ int const x = xo_;
+ int const y = yo_ < 0 ? 0 : yo_;
+ int const h = yo_ < 0 ? row_.height() + yo_ : row_.height();
+ pain_.fillRectangle(x, y, width_, h, text_.backgroundColor());
}
if ((startrow != row && !is_rtl) || (endrow != row && is_rtl))
pain_.fillRectangle(xo_, yo_, int(x_), row_.height(), LColor::selection);
- pos_type const main_body = par_.beginningOfMainBody();
+ pos_type const body_pos = par_.beginningOfBody();
pos_type const last = row_.lastPrintablePos();
float tmpx = x_;
for (pos_type vpos = row_.pos(); vpos <= last; ++vpos) {
pos_type pos = text_.vis2log(vpos);
float const old_tmpx = tmpx;
- if (main_body > 0 && pos == main_body - 1) {
+ if (body_pos > 0 && pos == body_pos - 1) {
LyXLayout_ptr const & layout = par_.layout();
LyXFont const lfont = getLabelFont();
tmpx += label_hfill_ + font_metrics::width(layout->labelsep, lfont);
- if (par_.isLineSeparator(main_body - 1))
- tmpx -= singleWidth(main_body - 1);
+ if (par_.isLineSeparator(body_pos - 1))
+ tmpx -= singleWidth(body_pos - 1);
}
if (row_.hfillExpansion(pos)) {
tmpx += singleWidth(pos);
- if (pos >= main_body)
+ if (pos >= body_pos)
tmpx += hfill_;
else
tmpx += label_hfill_;
else if (par_.isSeparator(pos)) {
tmpx += singleWidth(pos);
- if (pos >= main_body)
+ if (pos >= body_pos)
tmpx += separator_;
} else {
tmpx += singleWidth(pos);
void RowPainter::paintAppendix()
{
+ if (!par_.params().appendix())
+ return;
+
// FIXME: can be just width_ ?
int const ww = bv_.workWidth();
- if (par_.params().appendix()) {
- pain_.line(1, yo_, 1, yo_ + row_.height(), LColor::appendixline);
- pain_.line(ww - 2, yo_, ww - 2, yo_ + row_.height(), LColor::appendixline);
- }
+ int y = yo_;
+
+ if (par_.params().startOfAppendix())
+ y += 2 * defaultRowHeight();
+
+ pain_.line(1, y, 1, yo_ + row_.height(), LColor::appendix);
+ pain_.line(ww - 2, y, ww - 2, yo_ + row_.height(), LColor::appendix);
}
}
+int RowPainter::paintAppendixStart(int y)
+{
+ LyXFont pb_font;
+ pb_font.setColor(LColor::appendix).decSize();
+
+ string const label = _("Appendix");
+ int w = 0;
+ int a = 0;
+ int d = 0;
+ font_metrics::rectText(label, pb_font, w, a, d);
+
+ int const text_start = xo_ + ((width_ - w) / 2);
+ int const text_end = text_start + w;
+
+ pain_.rectText(text_start, y + d, label, pb_font);
+
+ pain_.line(xo_ + 1, y, text_start, y, LColor::appendix);
+ pain_.line(text_end, y, xo_ + width_ - 2, y, LColor::appendix);
+
+ return 3 * defaultRowHeight();
+}
+
+
void RowPainter::paintFirst()
{
ParagraphParameters const & parparams = par_.params();
+ int y_top = 0;
+
// start of appendix?
if (parparams.startOfAppendix()) {
- pain_.line(1, yo_, width_ - 2, yo_, LColor::appendixline);
+ y_top += paintAppendixStart(yo_ + y_top + 2 * defaultRowHeight());
}
- int y_top = 0;
-
// the top margin
- if (!row_.previous() && text_.isTopLevel())
+ if (!row_.previous() && !text_.isInInset())
y_top += PAPER_MARGIN;
// draw a top pagebreak
int y_bottom = row_.height() - 1;
// the bottom margin
- if (!row_.next() && text_.isTopLevel())
+ if (!row_.next() && !text_.isInInset())
y_bottom -= PAPER_MARGIN;
int const ww = bv_.workWidth();
}
-bool RowPainter::paintText()
+void RowPainter::paintText()
{
pos_type const last = row_.lastPrintablePos();
- pos_type main_body = par_.beginningOfMainBody();
- if (main_body > 0 &&
- (main_body - 1 > last ||
- !par_.isLineSeparator(main_body - 1))) {
- main_body = 0;
+ pos_type body_pos = par_.beginningOfBody();
+ if (body_pos > 0 &&
+ (body_pos - 1 > last ||
+ !par_.isLineSeparator(body_pos - 1))) {
+ body_pos = 0;
}
LyXLayout_ptr const & layout = par_.layout();
break;
pos_type pos = text_.vis2log(vpos);
+ if (pos >= par_.size()) {
+ ++vpos;
+ continue;
+ }
+
if (x_ + singleWidth(pos) < 0) {
x_ += singleWidth(pos);
++vpos;
running_strikeout = false;
}
- if (main_body > 0 && pos == main_body - 1) {
+ if (body_pos > 0 && pos == body_pos - 1) {
int const lwidth = font_metrics::width(layout->labelsep,
getLabelFont());
x_ += label_hfill_ + lwidth
- - singleWidth(main_body - 1);
+ - singleWidth(body_pos - 1);
}
if (par_.isHfill(pos)) {
if (row_.hfillExpansion(pos)) {
int const y2 = (y0 + y1) / 2;
- if (pos >= main_body) {
+ if (pos >= body_pos) {
pain_.line(int(x_), y2,
int(x_ + hfill_), y2,
LColor::added_space,
++vpos;
} else if (par_.isSeparator(pos)) {
x_ += singleWidth(pos);
- if (pos >= main_body)
+ if (pos >= body_pos)
x_ += separator_;
++vpos;
} else {
- if (paintFromPos(vpos))
- return true;
+ paintFromPos(vpos);
}
}
LColor::strikeout, Painter::line_solid, Painter::line_thin);
running_strikeout = false;
}
- return false;
+ return;
}
-bool RowPainter::paint(int y_offset, int x_offset, int y, bool cleared)
+void RowPainter::paint(int y_offset, int x_offset, int y)
{
xo_ = x_offset;
yo_ = y_offset;
y_ = y;
- cleared_ = cleared;
width_ = text_.isInInset()
? text_.inset_owner->textWidth(perv(bv_), true) : bv_.workWidth();
// FIXME: must be a cleaner way here. Aren't these calculations
// belonging to row metrics ?
- BufferView * bv(const_cast<BufferView *>(&bv_));
Row * row(const_cast<Row *>(&row_));
- text_.prepareToPrint(bv, row, x_, separator_, hfill_, label_hfill_);
+ text_.prepareToPrint(row, x_, separator_, hfill_, label_hfill_);
// FIXME: what is this fixing ?
if (text_.isInInset() && (x_ < 0))
x_ = 0;
x_ += xo_;
- // clear to background if necessary
- cleared_ = paintBackground();
+ // If we're *not* at the top-level of rows, then the
+ // background has already been cleared.
+ if (&text_ == bv_.text)
+ paintBackground();
// paint the selection background
if (text_.selection.set()) {
}
// paint text
- return paintText();
+ paintText();
}