3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
14 #include "rowpainter.h"
17 #include "coordcache.h"
20 #include "bufferparams.h"
21 #include "BufferView.h"
28 #include "metricsinfo.h"
29 #include "paragraph.h"
30 #include "paragraph_funcs.h"
31 #include "ParagraphParameters.h"
34 #include "frontends/FontMetrics.h"
35 #include "frontends/Painter.h"
37 #include "insets/insettext.h"
39 #include "support/textutils.h"
41 #include <boost/crc.hpp>
46 using frontend::Painter;
47 using frontend::FontMetrics;
57 /// Flag: do a full redraw of inside text of inset
58 /// Working variable indicating a full screen refresh
62 * A class used for painting an individual row of text.
66 /// initialise and run painter
67 RowPainter(PainterInfo & pi, LyXText const & text,
68 pit_type pit, Row const & row, int x, int y);
70 // paint various parts
73 void paintChangeBar();
79 void paintForeignMark(double orig_x, LyXFont const & font, int desc = 0);
80 void paintHebrewComposeChar(pos_type & vpos, LyXFont const & font);
81 void paintArabicComposeChar(pos_type & vpos, LyXFont const & font);
82 void paintChars(pos_type & vpos, LyXFont const & font,
83 bool hebrew, bool arabic);
84 int paintAppendixStart(int y);
85 void paintFromPos(pos_type & vpos);
86 void paintInset(pos_type const pos, LyXFont const & font);
88 /// return left margin
89 int leftMargin() const;
91 /// return the label font for this row
92 LyXFont const getLabelFont() const;
94 /// bufferview to paint on
100 /// LyXText for the row
101 LyXText const & text_;
102 ParagraphList const & pars_;
109 Paragraph const & par_;
111 /// is row erased? (change tracking)
116 int const yo_; // current baseline
125 RowPainter::RowPainter(PainterInfo & pi,
126 LyXText const & text, pit_type pit, Row const & row, int x, int y)
127 : bv_(*pi.base.bv), pain_(pi.pain), text_(text), pars_(text.paragraphs()),
128 row_(row), pit_(pit), par_(text.paragraphs()[pit]),
130 xo_(x), yo_(y), width_(text_.width())
132 RowMetrics m = text_.computeRowMetrics(*bv_.buffer(), pit, row_);
135 //lyxerr << "RowPainter: x: " << x_ << " xo: " << xo_ << " yo: " << yo_ << endl;
138 separator_ = m.separator;
140 label_hfill_ = m.label_hfill;
142 BOOST_ASSERT(pit >= 0);
143 BOOST_ASSERT(pit < int(text.paragraphs().size()));
147 LyXFont const RowPainter::getLabelFont() const
149 return text_.getLabelFont(*bv_.buffer(), par_);
153 int RowPainter::leftMargin() const
155 return text_.leftMargin(*bv_.buffer(), pit_, row_.pos());
159 // If you want to debug inset metrics uncomment the following line:
160 // #define DEBUG_METRICS
161 // This draws green lines around each inset.
164 void RowPainter::paintInset(pos_type const pos, LyXFont const & font)
166 InsetBase const * inset = par_.getInset(pos);
168 PainterInfo pi(const_cast<BufferView *>(&bv_), pain_);
169 // FIXME: We should always use font, see documentation of
170 // noFontChange() in insetbase.h.
171 pi.base.font = inset->noFontChange() ?
172 bv_.buffer()->params().getFont() :
174 pi.ltr_pos = (text_.bidi.level(pos) % 2 == 0);
175 pi.erased_ = erased_ || par_.isDeleted(pos);
177 int const x1 = int(x_);
179 bv_.coordCache().insets().add(inset, int(x_), yo_);
180 InsetText const * const in = inset->asTextInset();
181 // non-wide insets are painted completely. Recursive
182 bool tmp = refreshInside;
183 if (!in || !in->wide()) {
184 refreshInside = true;
185 lyxerr[Debug::PAINTING] << endl << "Paint inset fully" << endl;
188 inset->drawSelection(pi, int(x_), yo_);
189 inset->draw(pi, int(x_), yo_);
191 x_ += inset->width();
194 BOOST_ASSERT(text_.maxwidth_ > 0);
195 int const w = text_.maxwidth_ - leftMargin() - text_.rightMargin(*bv_.buffer(), par_);
196 MetricsInfo mi(&bv_, font, w);
197 inset->metrics(mi, dim);
198 if (inset->width() > dim.wid)
199 lyxerr << "Error: inset " << to_ascii(inset->getInsetName())
200 << " draw width " << inset->width()
201 << "> metrics width " << dim.wid << "." << std::endl;
202 if (inset->ascent() > dim.asc)
203 lyxerr << "Error: inset " << to_ascii(inset->getInsetName())
204 << " draw ascent " << inset->ascent()
205 << "> metrics ascent " << dim.asc << "." << std::endl;
206 if (inset->descent() > dim.des)
207 lyxerr << "Error: inset " << to_ascii(inset->getInsetName())
208 << " draw ascent " << inset->descent()
209 << "> metrics descent " << dim.des << "." << std::endl;
210 BOOST_ASSERT(inset->width() <= dim.wid);
211 BOOST_ASSERT(inset->ascent() <= dim.asc);
212 BOOST_ASSERT(inset->descent() <= dim.des);
213 int const x2 = x1 + dim.wid;
214 int const y1 = yo_ + dim.des;
215 int const y2 = yo_ - dim.asc;
216 pi.pain.line(x1, y1, x1, y2, LColor::green);
217 pi.pain.line(x1, y1, x2, y1, LColor::green);
218 pi.pain.line(x2, y1, x2, y2, LColor::green);
219 pi.pain.line(x1, y2, x2, y2, LColor::green);
224 void RowPainter::paintHebrewComposeChar(pos_type & vpos, LyXFont const & font)
226 pos_type pos = text_.bidi.vis2log(vpos);
231 char_type c = par_.getChar(pos);
235 int const width = theFontMetrics(font).width(c);
238 for (pos_type i = pos - 1; i >= 0; --i) {
240 if (!Encodings::isComposeChar_hebrew(c)) {
241 if (isPrintableNonspace(c)) {
242 int const width2 = text_.singleWidth(par_, i, c,
243 text_.getFont(*bv_.buffer(), par_, i));
245 // This does not work anymore, and non-ascii
246 // characters in source files are forbidden
249 dx = (c == 'ø' || c == 'ã')
251 : (width2 - width) / 2;
259 pain_.text(int(x_) + dx, yo_, str, font);
263 void RowPainter::paintArabicComposeChar(pos_type & vpos, LyXFont const & font)
265 pos_type pos = text_.bidi.vis2log(vpos);
269 char_type c = par_.getChar(pos);
270 c = par_.transformChar(c, pos);
274 int const width = theFontMetrics(font).width(c);
277 for (pos_type i = pos - 1; i >= 0; --i) {
279 if (!Encodings::isComposeChar_arabic(c)) {
280 if (isPrintableNonspace(c)) {
281 int const width2 = text_.singleWidth(par_, i, c,
282 text_.getFont(*bv_.buffer(), par_, i));
283 dx = (width2 - width) / 2;
289 pain_.text(int(x_) + dx, yo_, str, font);
292 void RowPainter::paintChars(pos_type & vpos, LyXFont const & font,
293 bool hebrew, bool arabic)
295 // This method takes up 70% of time when typing
296 pos_type pos = text_.bidi.vis2log(vpos);
297 pos_type const end = row_.endpos();
298 FontSpan const font_span = par_.fontSpan(pos);
299 Change::Type const prev_change = par_.lookupChange(pos).type;
302 std::vector<char_type> str;
304 str.push_back(par_.getChar(pos));
307 char_type c = str[0];
308 str[0] = par_.transformChar(c, pos);
311 // collect as much similar chars as we can
312 for (++vpos ; vpos < end ; ++vpos) {
313 pos = text_.bidi.vis2log(vpos);
314 if (pos < font_span.first || pos > font_span.last)
317 if (prev_change != par_.lookupChange(pos).type)
320 char_type c = par_.getChar(pos);
322 if (!isPrintableNonspace(c))
325 if (arabic && Encodings::isComposeChar_arabic(c))
328 if (hebrew && Encodings::isComposeChar_hebrew(c))
332 c = par_.transformChar(c, pos);
337 if (prev_change != Change::UNCHANGED) {
339 if (prev_change == Change::DELETED) {
340 copy.setColor(LColor::strikeout);
341 } else if (prev_change == Change::INSERTED) {
342 copy.setColor(LColor::newtext);
344 x_ += pain_.text(int(x_), yo_, &str[0], str.size(), copy);
346 x_ += pain_.text(int(x_), yo_, &str[0], str.size(), font);
351 void RowPainter::paintForeignMark(double orig_x, LyXFont const & font, int desc)
353 if (!lyxrc.mark_foreign_language)
355 if (font.language() == latex_language)
357 if (font.language() == bv_.buffer()->params().language)
360 int const y = yo_ + 1 + desc;
361 pain_.line(int(orig_x), y, int(x_), y, LColor::language);
365 void RowPainter::paintFromPos(pos_type & vpos)
367 pos_type const pos = text_.bidi.vis2log(vpos);
368 LyXFont orig_font = text_.getFont(*bv_.buffer(), par_, pos);
370 double const orig_x = x_;
372 if (par_.isInset(pos)) {
373 paintInset(pos, orig_font);
375 paintForeignMark(orig_x, orig_font,
376 par_.getInset(pos)->descent());
380 // usual characters, no insets
381 char_type const c = par_.getChar(pos);
383 // special case languages
384 std::string const & lang = orig_font.language()->lang();
385 bool const hebrew = lang == "hebrew";
386 bool const arabic = lang == "arabic" &&
387 (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
388 lyxrc.font_norm_type == LyXRC::ISO_10646_1);
390 // draw as many chars as we can
391 if ((!hebrew && !arabic)
392 || (hebrew && !Encodings::isComposeChar_hebrew(c))
393 || (arabic && !Encodings::isComposeChar_arabic(c))) {
394 paintChars(vpos, orig_font, hebrew, arabic);
396 paintHebrewComposeChar(vpos, orig_font);
398 paintArabicComposeChar(vpos, orig_font);
401 paintForeignMark(orig_x, orig_font);
405 void RowPainter::paintChangeBar()
407 pos_type const start = row_.pos();
408 pos_type end = row_.endpos();
410 if (par_.size() == end) {
411 // this is the last row of the paragraph;
412 // thus, we must also consider the imaginary end-of-par character
416 if (start == end || !par_.isChanged(start, end))
419 int const height = text_.isLastRow(pit_, row_)
423 pain_.fillRectangle(5, yo_ - row_.ascent(), 3, height, LColor::changebar);
427 void RowPainter::paintAppendix()
429 if (!par_.params().appendix())
432 int y = yo_ - row_.ascent();
434 if (par_.params().startOfAppendix())
435 y += 2 * defaultRowHeight();
437 pain_.line(1, y, 1, yo_ + row_.height(), LColor::appendix);
438 pain_.line(width_ - 2, y, width_ - 2, yo_ + row_.height(), LColor::appendix);
442 void RowPainter::paintDepthBar()
444 depth_type const depth = par_.getDepth();
449 depth_type prev_depth = 0;
450 if (!text_.isFirstRow(pit_, row_)) {
451 pit_type pit2 = pit_;
454 prev_depth = pars_[pit2].getDepth();
457 depth_type next_depth = 0;
458 if (!text_.isLastRow(pit_, row_)) {
459 pit_type pit2 = pit_;
460 if (row_.endpos() >= pars_[pit2].size())
462 next_depth = pars_[pit2].getDepth();
465 for (depth_type i = 1; i <= depth; ++i) {
466 int const w = nestMargin() / 5;
467 int x = int(xo_) + w * i;
468 // only consider the changebar space if we're drawing outermost text
469 if (text_.isMainText(*bv_.buffer()))
470 x += changebarMargin();
472 int const starty = yo_ - row_.ascent();
473 int const h = row_.height() - 1 - (i - next_depth - 1) * 3;
475 pain_.line(x, starty, x, starty + h, LColor::depthbar);
478 pain_.fillRectangle(x, starty, w, 2, LColor::depthbar);
480 pain_.fillRectangle(x, starty + h, w, 2, LColor::depthbar);
485 int RowPainter::paintAppendixStart(int y)
488 pb_font.setColor(LColor::appendix);
495 docstring const label = _("Appendix");
496 theFontMetrics(pb_font).rectText(label, w, a, d);
498 int const text_start = int(xo_ + (width_ - w) / 2);
499 int const text_end = text_start + w;
501 pain_.rectText(text_start, y + d, label, pb_font, LColor::none, LColor::none);
503 pain_.line(int(xo_ + 1), y, text_start, y, LColor::appendix);
504 pain_.line(text_end, y, int(xo_ + width_ - 2), y, LColor::appendix);
506 return 3 * defaultRowHeight();
510 void RowPainter::paintFirst()
512 ParagraphParameters const & parparams = par_.params();
516 // start of appendix?
517 if (parparams.startOfAppendix())
518 y_top += paintAppendixStart(yo_ - row_.ascent() + 2 * defaultRowHeight());
520 Buffer const & buffer = *bv_.buffer();
522 LyXLayout_ptr const & layout = par_.layout();
524 if (buffer.params().paragraph_separation == BufferParams::PARSEP_SKIP) {
526 if (layout->latextype == LATEX_PARAGRAPH
527 && !par_.getDepth()) {
528 y_top += buffer.params().getDefSkip().inPixels(bv_);
530 LyXLayout_ptr const & playout = pars_[pit_ - 1].layout();
531 if (playout->latextype == LATEX_PARAGRAPH
532 && !pars_[pit_ - 1].getDepth()) {
533 // is it right to use defskip here, too? (AS)
534 y_top += buffer.params().getDefSkip().inPixels(bv_);
540 bool const is_rtl = text_.isRTL(buffer, par_);
541 bool const is_seq = isFirstInSequence(pit_, text_.paragraphs());
542 //lyxerr << "paintFirst: " << par_.id() << " is_seq: " << is_seq << std::endl;
544 // should we print a label?
545 if (layout->labeltype >= LABEL_STATIC
546 && (layout->labeltype != LABEL_STATIC
547 || layout->latextype != LATEX_ENVIRONMENT
550 LyXFont const font = getLabelFont();
551 FontMetrics const & fm = theFontMetrics(font);
553 docstring const str = par_.getLabelstring();
557 // this is special code for the chapter layout. This is
558 // printed in an extra row and has a pagebreak at
560 if (layout->counter == "chapter") {
561 double spacing_val = 1.0;
562 if (!parparams.spacing().isDefault()) {
563 spacing_val = parparams.spacing().getValue();
565 spacing_val = buffer.params().spacing().getValue();
568 int const labeladdon = int(fm.maxHeight() * layout->spacing.getValue() * spacing_val);
570 int const maxdesc = int(fm.maxDescent() * layout->spacing.getValue() * spacing_val)
571 + int(layout->parsep) * defaultRowHeight();
574 x = width_ - leftMargin() -
578 pain_.text(int(x), yo_ - maxdesc - labeladdon, str, font);
581 docstring lab = from_utf8(layout->labelsep);
583 x = width_ - leftMargin()
586 x = x_ - fm.width(lab)
590 pain_.text(int(x), yo_, str, font);
594 // the labels at the top of an environment.
595 // More or less for bibliography
597 (layout->labeltype == LABEL_TOP_ENVIRONMENT ||
598 layout->labeltype == LABEL_BIBLIO ||
599 layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)) {
600 LyXFont font = getLabelFont();
601 if (!par_.getLabelstring().empty()) {
602 docstring const str = par_.getLabelstring();
603 double spacing_val = 1.0;
604 if (!parparams.spacing().isDefault())
605 spacing_val = parparams.spacing().getValue();
607 spacing_val = buffer.params().spacing().getValue();
609 FontMetrics const & fm = theFontMetrics(font);
611 int const labeladdon = int(fm.maxHeight()
612 * layout->spacing.getValue() * spacing_val);
615 int(fm.maxDescent() * layout->spacing.getValue() * spacing_val
616 + (layout->labelbottomsep * defaultRowHeight()));
619 if (layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
622 x += (width_ - text_.rightMargin(buffer, par_) - leftMargin()) / 2;
623 x -= fm.width(str) / 2;
625 x = width_ - leftMargin() - fm.width(str);
627 pain_.text(int(x), yo_ - maxdesc - labeladdon, str, font);
633 void RowPainter::paintLast()
635 bool const is_rtl = text_.isRTL(*bv_.buffer(), par_);
636 int const endlabel = getEndLabel(pit_, text_.paragraphs());
641 case END_LABEL_FILLED_BOX: {
642 LyXFont const font = getLabelFont();
643 FontMetrics const & fm = theFontMetrics(font);
644 int const size = int(0.75 * fm.maxAscent());
645 int const y = yo_ - size;
646 int x = is_rtl ? nestMargin() + changebarMargin() : width_ - size;
648 if (width_ - int(row_.width()) <= size)
649 x += (size - width_ + row_.width() + 1) * (is_rtl ? -1 : 1);
651 if (endlabel == END_LABEL_BOX)
652 pain_.rectangle(x, y, size, size, LColor::eolmarker);
654 pain_.fillRectangle(x, y, size, size, LColor::eolmarker);
658 case END_LABEL_STATIC: {
659 LyXFont font = getLabelFont();
660 FontMetrics const & fm = theFontMetrics(font);
661 docstring const & str = par_.layout()->endlabelstring();
662 double const x = is_rtl ?
664 : - text_.rightMargin(*bv_.buffer(), par_) - row_.width();
665 pain_.text(int(x), yo_, str, font);
669 case END_LABEL_NO_LABEL:
675 void RowPainter::paintText()
677 pos_type const end = row_.endpos();
678 pos_type body_pos = par_.beginOfBody();
680 (body_pos > end || !par_.isLineSeparator(body_pos - 1))) {
684 LyXLayout_ptr const & layout = par_.layout();
686 bool running_strikeout = false;
687 bool is_struckout = false;
688 int last_strikeout_x = 0;
690 // Use font span to speed things up, see below
693 Buffer const & buffer = *bv_.buffer();
695 for (pos_type vpos = row_.pos(); vpos < end; ) {
696 if (x_ > bv_.workWidth())
699 pos_type const pos = text_.bidi.vis2log(vpos);
701 if (pos >= par_.size()) {
706 // Use font span to speed things up, see above
707 if (vpos < font_span.first || vpos > font_span.last) {
708 font_span = par_.fontSpan(vpos);
709 font = text_.getFont(buffer, par_, vpos);
712 const int width_pos =
713 text_.singleWidth(par_, pos, par_.getChar(pos), font);
715 if (x_ + width_pos < 0) {
721 is_struckout = par_.isDeleted(pos);
723 if (is_struckout && !running_strikeout) {
724 running_strikeout = true;
725 last_strikeout_x = int(x_);
728 bool const highly_editable_inset = par_.isInset(pos)
729 && isHighlyEditableInset(par_.getInset(pos));
731 // If we reach the end of a struck out range, paint it.
732 // We also don't paint across things like tables
733 if (running_strikeout && (highly_editable_inset || !is_struckout)) {
734 // Calculate 1/3 height of the buffer's default font
735 FontMetrics const & fm
736 = theFontMetrics(bv_.buffer()->params().getFont());
737 int const middle = yo_ - fm.maxAscent() / 3;
738 pain_.line(last_strikeout_x, middle, int(x_), middle,
739 LColor::strikeout, Painter::line_solid, Painter::line_thin);
740 running_strikeout = false;
743 if (body_pos > 0 && pos == body_pos - 1) {
745 int const lwidth = theFontMetrics(getLabelFont())
746 .width(from_utf8(layout->labelsep));
748 x_ += label_hfill_ + lwidth - width_pos;
751 if (par_.isHfill(pos)) {
755 int const y1 = y0 - defaultRowHeight() / 2;
757 pain_.line(int(x_), y1, int(x_), y0, LColor::added_space);
759 if (par_.hfillExpansion(row_, pos)) {
760 int const y2 = (y0 + y1) / 2;
762 if (pos >= body_pos) {
763 pain_.line(int(x_), y2, int(x_ + hfill_), y2,
765 Painter::line_onoffdash);
768 pain_.line(int(x_), y2, int(x_ + label_hfill_), y2,
770 Painter::line_onoffdash);
773 pain_.line(int(x_), y1, int(x_), y0, LColor::added_space);
777 } else if (par_.isSeparator(pos)) {
787 // if we reach the end of a struck out range, paint it
788 if (running_strikeout) {
789 // calculate 1/3 height of the buffer's default font
790 FontMetrics const & fm
791 = theFontMetrics(bv_.buffer()->params().getFont());
792 int const middle = yo_ - fm.maxAscent() / 3;
793 pain_.line(last_strikeout_x, middle, int(x_), middle,
794 LColor::strikeout, Painter::line_solid, Painter::line_thin);
795 running_strikeout = false;
800 size_type calculateRowSignature(Row const & row, Paragraph const & par,
803 boost::crc_32_type crc;
804 for (pos_type i = row.pos(); i < row.endpos(); ++i) {
805 char_type const b[] = { par.getChar(i) };
806 crc.process_bytes(b, 1);
808 char_type const b[] = { x, y, row.width() };
809 crc.process_bytes(b, 3);
810 return crc.checksum();
814 bool CursorOnRow(PainterInfo & pi, pit_type const pit,
815 RowList::const_iterator rit, LyXText const & text)
817 // Is there a cursor on this row (or inside inset on row)
818 LCursor & cur = pi.base.bv->cursor();
819 for (size_type d = 0; d < cur.depth(); ++d) {
820 CursorSlice const & sl = cur[d];
821 if (sl.text() == &text
823 && sl.pos() >= rit->pos()
824 && sl.pos() <= rit->endpos())
831 bool innerCursorOnRow(PainterInfo & pi, pit_type pit,
832 RowList::const_iterator rit, LyXText const & text)
834 // Is there a cursor inside an inset on this row, and is this inset
835 // the only "character" on this row
836 LCursor & cur = pi.base.bv->cursor();
837 if (rit->pos() + 1 != rit->endpos())
839 for (size_type d = 0; d < cur.depth(); d++) {
840 CursorSlice const & sl = cur[d];
841 if (sl.text() == &text
843 && sl.pos() == rit->pos())
844 return d < cur.depth() - 1;
851 (PainterInfo & pi, LyXText const & text, pit_type pit, int x, int y,
854 // lyxerr << " paintPar: pit: " << pit << " at y: " << y << endl;
855 int const ww = pi.base.bv->workHeight();
857 pi.base.bv->coordCache().parPos()[&text][pit] = Point(x, y);
859 Paragraph const & par = text.paragraphs()[pit];
860 if (par.rows().empty())
863 RowList::const_iterator const rb = par.rows().begin();
864 RowList::const_iterator const re = par.rows().end();
868 for (RowList::const_iterator rit = rb; rit != re; ++rit, ++rowno) {
870 // Allow setting of refreshInside for nested insets in
872 bool tmp = refreshInside;
874 // Row signature; has row changed since last paint?
875 size_type const row_sig = calculateRowSignature(*rit, par, x, y);
876 bool row_has_changed = par.rowSignature()[rowno] != row_sig;
878 bool cursor_on_row = CursorOnRow(pi, pit, rit, text);
879 bool in_inset_alone_on_row = innerCursorOnRow(pi, pit, rit,
882 // If this is the only object on the row, we can make it wide
884 // FIXME: there is a const_cast here because paintPar() is not supposed
885 // to touch the paragraph contents. So either we move this "wide"
886 // property out of InsetText or we localize the feature to the painting
888 for (pos_type i = rit->pos() ; i != rit->endpos(); ++i) {
889 InsetBase const * const in = par.getInset(i);
891 InsetText * t = const_cast<InsetText *>(in->asTextInset());
893 t->setWide(in_inset_alone_on_row);
897 // If selection is on, the current row signature differs
898 // from cache, or cursor is inside an inset _on this row_,
899 // then paint the row
900 if (repaintAll || row_has_changed || cursor_on_row) {
901 // Add to row signature cache
902 par.rowSignature()[rowno] = row_sig;
904 bool const inside = (y + rit->descent() >= 0
905 && y - rit->ascent() < ww);
906 // it is not needed to draw on screen if we are not inside.
907 pi.pain.setDrawingEnabled(inside);
908 RowPainter rp(pi, text, pit, *rit, x, y);
909 // Clear background of this row
910 // (if paragraph background was not cleared)
912 (!in_inset_alone_on_row || row_has_changed)) {
913 pi.pain.fillRectangle(x, y - rit->ascent(),
914 text.maxwidth_, rit->height(),
915 text.backgroundColor());
916 // If outer row has changed, force nested
917 // insets to repaint completely
919 refreshInside = true;
922 // Instrumentation for testing row cache (see also
924 if (text.isMainText(*pi.base.bv->buffer()))
925 lyxerr[Debug::PAINTING] << "#";
927 lyxerr[Debug::PAINTING] << "[" <<
928 repaintAll << row_has_changed <<
929 cursor_on_row << "]";
940 // Restore, see above
943 // Re-enable screen drawing for future use of the painter.
944 pi.pain.setDrawingEnabled(true);
946 lyxerr[Debug::PAINTING] << "." << endl;
952 void paintText(BufferView & bv,
955 BOOST_ASSERT(bv.buffer());
956 Buffer const & buffer = *bv.buffer();
957 LyXText & text = buffer.text();
958 bool const select = bv.cursor().selection();
959 ViewMetricsInfo const & vi = bv.viewMetricsInfo();
961 PainterInfo pi(const_cast<BufferView *>(&bv), pain);
962 // Should the whole screen, including insets, be refreshed?
963 bool repaintAll = select || !vi.singlepar;
966 // Clear background (if not delegated to rows)
967 pain.fillRectangle(0, vi.y1, bv.workWidth(), vi.y2 - vi.y1,
968 text.backgroundColor());
971 text.drawSelection(pi, 0, 0);
976 for (pit_type pit = vi.p1; pit <= vi.p2; ++pit) {
977 refreshInside = repaintAll;
978 Paragraph const & par = text.getPar(pit);
980 paintPar(pi, text, pit, 0, yy, repaintAll);
984 // Cache one paragraph above and one below
985 // Note MV: this cannot be suppressed even for singlepar.
986 // Try viewing the User Guide Mobius figure
989 text.redoParagraph(bv, vi.p1 - 1);
990 bv.coordCache().parPos()[&text][vi.p1 - 1] =
991 Point(0, vi.y1 - text.getPar(vi.p1 - 1).descent());
994 if (vi.p2 < pit_type(text.paragraphs().size()) - 1) {
995 text.redoParagraph(bv, vi.p2 + 1);
996 bv.coordCache().parPos()[&text][vi.p2 + 1] =
997 Point(0, vi.y2 + text.getPar(vi.p2 + 1).ascent());
1000 // and grey out above (should not happen later)
1001 // lyxerr << "par ascent: " << text.getPar(vi.p1).ascent() << endl;
1002 if (vi.y1 > 0 && !vi.singlepar)
1003 pain.fillRectangle(0, 0, bv.workWidth(), vi.y1, LColor::bottomarea);
1005 // and possibly grey out below
1006 // lyxerr << "par descent: " << text.getPar(vi.p1).ascent() << endl;
1007 if (vi.y2 < bv.workHeight() && !vi.singlepar)
1008 pain.fillRectangle(0, vi.y2, bv.workWidth(), bv.workHeight() - vi.y2, LColor::bottomarea);
1012 void paintTextInset(LyXText const & text, PainterInfo & pi, int x, int y)
1014 // lyxerr << " paintTextInset: y: " << y << endl;
1016 y -= text.getPar(0).ascent();
1017 // This flag can not be set from within same inset:
1018 bool repaintAll = refreshInside;
1019 for (int pit = 0; pit < int(text.paragraphs().size()); ++pit) {
1020 y += text.getPar(pit).ascent();
1021 paintPar(pi, text, pit, x, y, repaintAll);
1022 y += text.getPar(pit).descent();