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 if (lyxerr.debugging(Debug::PAINTING)) {
186 lyxerr << endl << "Paint inset fully" << endl;
190 inset->drawSelection(pi, int(x_), yo_);
191 inset->draw(pi, int(x_), yo_);
193 x_ += inset->width();
196 BOOST_ASSERT(text_.maxwidth_ > 0);
197 int const w = text_.maxwidth_ - leftMargin() - text_.rightMargin(*bv_.buffer(), par_);
198 MetricsInfo mi(&bv_, font, w);
199 inset->metrics(mi, dim);
200 if (inset->width() > dim.wid)
201 lyxerr << "Error: inset " << to_ascii(inset->getInsetName())
202 << " draw width " << inset->width()
203 << "> metrics width " << dim.wid << "." << std::endl;
204 if (inset->ascent() > dim.asc)
205 lyxerr << "Error: inset " << to_ascii(inset->getInsetName())
206 << " draw ascent " << inset->ascent()
207 << "> metrics ascent " << dim.asc << "." << std::endl;
208 if (inset->descent() > dim.des)
209 lyxerr << "Error: inset " << to_ascii(inset->getInsetName())
210 << " draw ascent " << inset->descent()
211 << "> metrics descent " << dim.des << "." << std::endl;
212 BOOST_ASSERT(inset->width() <= dim.wid);
213 BOOST_ASSERT(inset->ascent() <= dim.asc);
214 BOOST_ASSERT(inset->descent() <= dim.des);
215 int const x2 = x1 + dim.wid;
216 int const y1 = yo_ + dim.des;
217 int const y2 = yo_ - dim.asc;
218 pi.pain.line(x1, y1, x1, y2, LColor::green);
219 pi.pain.line(x1, y1, x2, y1, LColor::green);
220 pi.pain.line(x2, y1, x2, y2, LColor::green);
221 pi.pain.line(x1, y2, x2, y2, LColor::green);
226 void RowPainter::paintHebrewComposeChar(pos_type & vpos, LyXFont const & font)
228 pos_type pos = text_.bidi.vis2log(vpos);
233 char_type c = par_.getChar(pos);
237 int const width = theFontMetrics(font).width(c);
240 for (pos_type i = pos - 1; i >= 0; --i) {
242 if (!Encodings::isComposeChar_hebrew(c)) {
243 if (isPrintableNonspace(c)) {
244 int const width2 = text_.singleWidth(par_, i, c,
245 text_.getFont(*bv_.buffer(), par_, i));
247 // This does not work anymore, and non-ascii
248 // characters in source files are forbidden
251 dx = (c == 'ø' || c == 'ã')
253 : (width2 - width) / 2;
261 pain_.text(int(x_) + dx, yo_, str, font);
265 void RowPainter::paintArabicComposeChar(pos_type & vpos, LyXFont const & font)
267 pos_type pos = text_.bidi.vis2log(vpos);
271 char_type c = par_.getChar(pos);
272 c = par_.transformChar(c, pos);
276 int const width = theFontMetrics(font).width(c);
279 for (pos_type i = pos - 1; i >= 0; --i) {
281 if (!Encodings::isComposeChar_arabic(c)) {
282 if (isPrintableNonspace(c)) {
283 int const width2 = text_.singleWidth(par_, i, c,
284 text_.getFont(*bv_.buffer(), par_, i));
285 dx = (width2 - width) / 2;
291 pain_.text(int(x_) + dx, yo_, str, font);
294 void RowPainter::paintChars(pos_type & vpos, LyXFont const & font,
295 bool hebrew, bool arabic)
297 // This method takes up 70% of time when typing
298 pos_type pos = text_.bidi.vis2log(vpos);
299 pos_type const end = row_.endpos();
300 FontSpan const font_span = par_.fontSpan(pos);
301 Change::Type const prev_change = par_.lookupChange(pos).type;
304 std::vector<char_type> str;
306 str.push_back(par_.getChar(pos));
309 char_type c = str[0];
310 str[0] = par_.transformChar(c, pos);
313 // collect as much similar chars as we can
314 for (++vpos ; vpos < end ; ++vpos) {
315 pos = text_.bidi.vis2log(vpos);
316 if (pos < font_span.first || pos > font_span.last)
319 if (prev_change != par_.lookupChange(pos).type)
322 char_type c = par_.getChar(pos);
324 if (!isPrintableNonspace(c))
327 if (arabic && Encodings::isComposeChar_arabic(c))
330 if (hebrew && Encodings::isComposeChar_hebrew(c))
334 c = par_.transformChar(c, pos);
339 if (prev_change != Change::UNCHANGED) {
341 if (prev_change == Change::DELETED) {
342 copy.setColor(LColor::strikeout);
343 } else if (prev_change == Change::INSERTED) {
344 copy.setColor(LColor::newtext);
346 x_ += pain_.text(int(x_), yo_, &str[0], str.size(), copy);
348 x_ += pain_.text(int(x_), yo_, &str[0], str.size(), font);
353 void RowPainter::paintForeignMark(double orig_x, LyXFont const & font, int desc)
355 if (!lyxrc.mark_foreign_language)
357 if (font.language() == latex_language)
359 if (font.language() == bv_.buffer()->params().language)
362 int const y = yo_ + 1 + desc;
363 pain_.line(int(orig_x), y, int(x_), y, LColor::language);
367 void RowPainter::paintFromPos(pos_type & vpos)
369 pos_type const pos = text_.bidi.vis2log(vpos);
370 LyXFont orig_font = text_.getFont(*bv_.buffer(), par_, pos);
372 double const orig_x = x_;
374 if (par_.isInset(pos)) {
375 paintInset(pos, orig_font);
377 paintForeignMark(orig_x, orig_font,
378 par_.getInset(pos)->descent());
382 // usual characters, no insets
383 char_type const c = par_.getChar(pos);
385 // special case languages
386 std::string const & lang = orig_font.language()->lang();
387 bool const hebrew = lang == "hebrew";
388 bool const arabic = lang == "arabic" &&
389 (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
390 lyxrc.font_norm_type == LyXRC::ISO_10646_1);
392 // draw as many chars as we can
393 if ((!hebrew && !arabic)
394 || (hebrew && !Encodings::isComposeChar_hebrew(c))
395 || (arabic && !Encodings::isComposeChar_arabic(c))) {
396 paintChars(vpos, orig_font, hebrew, arabic);
398 paintHebrewComposeChar(vpos, orig_font);
400 paintArabicComposeChar(vpos, orig_font);
403 paintForeignMark(orig_x, orig_font);
407 void RowPainter::paintChangeBar()
409 pos_type const start = row_.pos();
410 pos_type end = row_.endpos();
412 if (par_.size() == end) {
413 // this is the last row of the paragraph;
414 // thus, we must also consider the imaginary end-of-par character
418 if (start == end || !par_.isChanged(start, end))
421 int const height = text_.isLastRow(pit_, row_)
425 pain_.fillRectangle(5, yo_ - row_.ascent(), 3, height, LColor::changebar);
429 void RowPainter::paintAppendix()
431 if (!par_.params().appendix())
434 int y = yo_ - row_.ascent();
436 if (par_.params().startOfAppendix())
437 y += 2 * defaultRowHeight();
439 pain_.line(1, y, 1, yo_ + row_.height(), LColor::appendix);
440 pain_.line(width_ - 2, y, width_ - 2, yo_ + row_.height(), LColor::appendix);
444 void RowPainter::paintDepthBar()
446 depth_type const depth = par_.getDepth();
451 depth_type prev_depth = 0;
452 if (!text_.isFirstRow(pit_, row_)) {
453 pit_type pit2 = pit_;
456 prev_depth = pars_[pit2].getDepth();
459 depth_type next_depth = 0;
460 if (!text_.isLastRow(pit_, row_)) {
461 pit_type pit2 = pit_;
462 if (row_.endpos() >= pars_[pit2].size())
464 next_depth = pars_[pit2].getDepth();
467 for (depth_type i = 1; i <= depth; ++i) {
468 int const w = nestMargin() / 5;
469 int x = int(xo_) + w * i;
470 // only consider the changebar space if we're drawing outermost text
471 if (text_.isMainText(*bv_.buffer()))
472 x += changebarMargin();
474 int const starty = yo_ - row_.ascent();
475 int const h = row_.height() - 1 - (i - next_depth - 1) * 3;
477 pain_.line(x, starty, x, starty + h, LColor::depthbar);
480 pain_.fillRectangle(x, starty, w, 2, LColor::depthbar);
482 pain_.fillRectangle(x, starty + h, w, 2, LColor::depthbar);
487 int RowPainter::paintAppendixStart(int y)
490 pb_font.setColor(LColor::appendix);
497 docstring const label = _("Appendix");
498 theFontMetrics(pb_font).rectText(label, w, a, d);
500 int const text_start = int(xo_ + (width_ - w) / 2);
501 int const text_end = text_start + w;
503 pain_.rectText(text_start, y + d, label, pb_font, LColor::none, LColor::none);
505 pain_.line(int(xo_ + 1), y, text_start, y, LColor::appendix);
506 pain_.line(text_end, y, int(xo_ + width_ - 2), y, LColor::appendix);
508 return 3 * defaultRowHeight();
512 void RowPainter::paintFirst()
514 ParagraphParameters const & parparams = par_.params();
518 // start of appendix?
519 if (parparams.startOfAppendix())
520 y_top += paintAppendixStart(yo_ - row_.ascent() + 2 * defaultRowHeight());
522 Buffer const & buffer = *bv_.buffer();
524 LyXLayout_ptr const & layout = par_.layout();
526 if (buffer.params().paragraph_separation == BufferParams::PARSEP_SKIP) {
528 if (layout->latextype == LATEX_PARAGRAPH
529 && !par_.getDepth()) {
530 y_top += buffer.params().getDefSkip().inPixels(bv_);
532 LyXLayout_ptr const & playout = pars_[pit_ - 1].layout();
533 if (playout->latextype == LATEX_PARAGRAPH
534 && !pars_[pit_ - 1].getDepth()) {
535 // is it right to use defskip here, too? (AS)
536 y_top += buffer.params().getDefSkip().inPixels(bv_);
542 bool const is_rtl = text_.isRTL(buffer, par_);
543 bool const is_seq = isFirstInSequence(pit_, text_.paragraphs());
544 //lyxerr << "paintFirst: " << par_.id() << " is_seq: " << is_seq << std::endl;
546 // should we print a label?
547 if (layout->labeltype >= LABEL_STATIC
548 && (layout->labeltype != LABEL_STATIC
549 || layout->latextype != LATEX_ENVIRONMENT
552 LyXFont const font = getLabelFont();
553 FontMetrics const & fm = theFontMetrics(font);
555 docstring const str = par_.getLabelstring();
559 // this is special code for the chapter layout. This is
560 // printed in an extra row and has a pagebreak at
562 if (layout->counter == "chapter") {
563 double spacing_val = 1.0;
564 if (!parparams.spacing().isDefault()) {
565 spacing_val = parparams.spacing().getValue();
567 spacing_val = buffer.params().spacing().getValue();
570 int const labeladdon = int(fm.maxHeight() * layout->spacing.getValue() * spacing_val);
572 int const maxdesc = int(fm.maxDescent() * layout->spacing.getValue() * spacing_val)
573 + int(layout->parsep) * defaultRowHeight();
576 x = width_ - leftMargin() -
580 pain_.text(int(x), yo_ - maxdesc - labeladdon, str, font);
583 docstring lab = from_utf8(layout->labelsep);
585 x = width_ - leftMargin()
588 x = x_ - fm.width(lab)
592 pain_.text(int(x), yo_, str, font);
596 // the labels at the top of an environment.
597 // More or less for bibliography
599 (layout->labeltype == LABEL_TOP_ENVIRONMENT ||
600 layout->labeltype == LABEL_BIBLIO ||
601 layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)) {
602 LyXFont font = getLabelFont();
603 if (!par_.getLabelstring().empty()) {
604 docstring const str = par_.getLabelstring();
605 double spacing_val = 1.0;
606 if (!parparams.spacing().isDefault())
607 spacing_val = parparams.spacing().getValue();
609 spacing_val = buffer.params().spacing().getValue();
611 FontMetrics const & fm = theFontMetrics(font);
613 int const labeladdon = int(fm.maxHeight()
614 * layout->spacing.getValue() * spacing_val);
617 int(fm.maxDescent() * layout->spacing.getValue() * spacing_val
618 + (layout->labelbottomsep * defaultRowHeight()));
621 if (layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
624 x += (width_ - text_.rightMargin(buffer, par_) - leftMargin()) / 2;
625 x -= fm.width(str) / 2;
627 x = width_ - leftMargin() - fm.width(str);
629 pain_.text(int(x), yo_ - maxdesc - labeladdon, str, font);
635 void RowPainter::paintLast()
637 bool const is_rtl = text_.isRTL(*bv_.buffer(), par_);
638 int const endlabel = getEndLabel(pit_, text_.paragraphs());
643 case END_LABEL_FILLED_BOX: {
644 LyXFont const font = getLabelFont();
645 FontMetrics const & fm = theFontMetrics(font);
646 int const size = int(0.75 * fm.maxAscent());
647 int const y = yo_ - size;
648 int x = is_rtl ? nestMargin() + changebarMargin() : width_ - size;
650 if (width_ - int(row_.width()) <= size)
651 x += (size - width_ + row_.width() + 1) * (is_rtl ? -1 : 1);
653 if (endlabel == END_LABEL_BOX)
654 pain_.rectangle(x, y, size, size, LColor::eolmarker);
656 pain_.fillRectangle(x, y, size, size, LColor::eolmarker);
660 case END_LABEL_STATIC: {
661 LyXFont font = getLabelFont();
662 FontMetrics const & fm = theFontMetrics(font);
663 docstring const & str = par_.layout()->endlabelstring();
664 double const x = is_rtl ?
666 : - text_.rightMargin(*bv_.buffer(), par_) - row_.width();
667 pain_.text(int(x), yo_, str, font);
671 case END_LABEL_NO_LABEL:
677 void RowPainter::paintText()
679 pos_type const end = row_.endpos();
680 pos_type body_pos = par_.beginOfBody();
682 (body_pos > end || !par_.isLineSeparator(body_pos - 1))) {
686 LyXLayout_ptr const & layout = par_.layout();
688 bool running_strikeout = false;
689 bool is_struckout = false;
690 int last_strikeout_x = 0;
692 // Use font span to speed things up, see below
695 Buffer const & buffer = *bv_.buffer();
697 for (pos_type vpos = row_.pos(); vpos < end; ) {
698 if (x_ > bv_.workWidth())
701 pos_type const pos = text_.bidi.vis2log(vpos);
703 if (pos >= par_.size()) {
708 // Use font span to speed things up, see above
709 if (vpos < font_span.first || vpos > font_span.last) {
710 font_span = par_.fontSpan(vpos);
711 font = text_.getFont(buffer, par_, vpos);
714 const int width_pos =
715 text_.singleWidth(par_, pos, par_.getChar(pos), font);
717 if (x_ + width_pos < 0) {
723 is_struckout = par_.isDeleted(pos);
725 if (is_struckout && !running_strikeout) {
726 running_strikeout = true;
727 last_strikeout_x = int(x_);
730 bool const highly_editable_inset = par_.isInset(pos)
731 && isHighlyEditableInset(par_.getInset(pos));
733 // If we reach the end of a struck out range, paint it.
734 // We also don't paint across things like tables
735 if (running_strikeout && (highly_editable_inset || !is_struckout)) {
736 // Calculate 1/3 height of the buffer's default font
737 FontMetrics const & fm
738 = theFontMetrics(bv_.buffer()->params().getFont());
739 int const middle = yo_ - fm.maxAscent() / 3;
740 pain_.line(last_strikeout_x, middle, int(x_), middle,
741 LColor::strikeout, Painter::line_solid, Painter::line_thin);
742 running_strikeout = false;
745 if (body_pos > 0 && pos == body_pos - 1) {
747 int const lwidth = theFontMetrics(getLabelFont())
748 .width(from_utf8(layout->labelsep));
750 x_ += label_hfill_ + lwidth - width_pos;
753 if (par_.isHfill(pos)) {
757 int const y1 = y0 - defaultRowHeight() / 2;
759 pain_.line(int(x_), y1, int(x_), y0, LColor::added_space);
761 if (par_.hfillExpansion(row_, pos)) {
762 int const y2 = (y0 + y1) / 2;
764 if (pos >= body_pos) {
765 pain_.line(int(x_), y2, int(x_ + hfill_), y2,
767 Painter::line_onoffdash);
770 pain_.line(int(x_), y2, int(x_ + label_hfill_), y2,
772 Painter::line_onoffdash);
775 pain_.line(int(x_), y1, int(x_), y0, LColor::added_space);
779 } else if (par_.isSeparator(pos)) {
789 // if we reach the end of a struck out range, paint it
790 if (running_strikeout) {
791 // calculate 1/3 height of the buffer's default font
792 FontMetrics const & fm
793 = theFontMetrics(bv_.buffer()->params().getFont());
794 int const middle = yo_ - fm.maxAscent() / 3;
795 pain_.line(last_strikeout_x, middle, int(x_), middle,
796 LColor::strikeout, Painter::line_solid, Painter::line_thin);
797 running_strikeout = false;
802 size_type calculateRowSignature(Row const & row, Paragraph const & par,
805 boost::crc_32_type crc;
806 for (pos_type i = row.pos(); i < row.endpos(); ++i) {
807 char_type const b[] = { par.getChar(i) };
808 crc.process_bytes(b, 1);
810 char_type const b[] = { x, y, row.width() };
811 crc.process_bytes(b, 3);
812 return crc.checksum();
816 bool CursorOnRow(PainterInfo & pi, pit_type const pit,
817 RowList::const_iterator rit, LyXText const & text)
819 // Is there a cursor on this row (or inside inset on row)
820 LCursor & cur = pi.base.bv->cursor();
821 for (size_type d = 0; d < cur.depth(); ++d) {
822 CursorSlice const & sl = cur[d];
823 if (sl.text() == &text
825 && sl.pos() >= rit->pos()
826 && sl.pos() <= rit->endpos())
833 bool innerCursorOnRow(PainterInfo & pi, pit_type pit,
834 RowList::const_iterator rit, LyXText const & text)
836 // Is there a cursor inside an inset on this row, and is this inset
837 // the only "character" on this row
838 LCursor & cur = pi.base.bv->cursor();
839 if (rit->pos() + 1 != rit->endpos())
841 for (size_type d = 0; d < cur.depth(); d++) {
842 CursorSlice const & sl = cur[d];
843 if (sl.text() == &text
845 && sl.pos() == rit->pos())
846 return d < cur.depth() - 1;
853 (PainterInfo & pi, LyXText const & text, pit_type pit, int x, int y,
856 // lyxerr << " paintPar: pit: " << pit << " at y: " << y << endl;
857 int const ww = pi.base.bv->workHeight();
859 pi.base.bv->coordCache().parPos()[&text][pit] = Point(x, y);
861 Paragraph const & par = text.paragraphs()[pit];
862 if (par.rows().empty())
865 RowList::const_iterator const rb = par.rows().begin();
866 RowList::const_iterator const re = par.rows().end();
870 for (RowList::const_iterator rit = rb; rit != re; ++rit, ++rowno) {
872 // Allow setting of refreshInside for nested insets in
874 bool tmp = refreshInside;
876 // Row signature; has row changed since last paint?
877 size_type const row_sig = calculateRowSignature(*rit, par, x, y);
878 bool row_has_changed = par.rowSignature()[rowno] != row_sig;
880 bool cursor_on_row = CursorOnRow(pi, pit, rit, text);
881 bool in_inset_alone_on_row = innerCursorOnRow(pi, pit, rit,
884 // If this is the only object on the row, we can make it wide
886 // FIXME: there is a const_cast here because paintPar() is not supposed
887 // to touch the paragraph contents. So either we move this "wide"
888 // property out of InsetText or we localize the feature to the painting
890 for (pos_type i = rit->pos() ; i != rit->endpos(); ++i) {
891 InsetBase const * const in = par.getInset(i);
893 InsetText * t = const_cast<InsetText *>(in->asTextInset());
895 t->setWide(in_inset_alone_on_row);
899 // If selection is on, the current row signature differs
900 // from cache, or cursor is inside an inset _on this row_,
901 // then paint the row
902 if (repaintAll || row_has_changed || cursor_on_row) {
903 // Add to row signature cache
904 par.rowSignature()[rowno] = row_sig;
906 bool const inside = (y + rit->descent() >= 0
907 && y - rit->ascent() < ww);
908 // it is not needed to draw on screen if we are not inside.
909 pi.pain.setDrawingEnabled(inside);
910 RowPainter rp(pi, text, pit, *rit, x, y);
911 // Clear background of this row
912 // (if paragraph background was not cleared)
914 (!in_inset_alone_on_row || row_has_changed)) {
915 pi.pain.fillRectangle(x, y - rit->ascent(),
916 text.maxwidth_, rit->height(),
917 text.backgroundColor());
918 // If outer row has changed, force nested
919 // insets to repaint completely
921 refreshInside = true;
924 // Instrumentation for testing row cache (see also
926 if (lyxerr.debugging(Debug::PAINTING)) {
927 if (text.isMainText(*pi.base.bv->buffer()))
928 lyxerr[Debug::PAINTING] << "#";
930 lyxerr[Debug::PAINTING] << "[" <<
931 repaintAll << row_has_changed <<
932 cursor_on_row << "]";
944 // Restore, see above
947 // Re-enable screen drawing for future use of the painter.
948 pi.pain.setDrawingEnabled(true);
950 if (lyxerr.debugging(Debug::PAINTING)) {
951 lyxerr[Debug::PAINTING] << "." << endl;
958 void paintText(BufferView & bv,
961 BOOST_ASSERT(bv.buffer());
962 Buffer const & buffer = *bv.buffer();
963 LyXText & text = buffer.text();
964 bool const select = bv.cursor().selection();
965 ViewMetricsInfo const & vi = bv.viewMetricsInfo();
967 PainterInfo pi(const_cast<BufferView *>(&bv), pain);
968 // Should the whole screen, including insets, be refreshed?
969 bool repaintAll = select || !vi.singlepar;
972 // Clear background (if not delegated to rows)
973 pain.fillRectangle(0, vi.y1, bv.workWidth(), vi.y2 - vi.y1,
974 text.backgroundColor());
977 text.drawSelection(pi, 0, 0);
982 for (pit_type pit = vi.p1; pit <= vi.p2; ++pit) {
983 refreshInside = repaintAll;
984 Paragraph const & par = text.getPar(pit);
986 paintPar(pi, text, pit, 0, yy, repaintAll);
990 // Cache one paragraph above and one below
991 // Note MV: this cannot be suppressed even for singlepar.
992 // Try viewing the User Guide Mobius figure
995 text.redoParagraph(bv, vi.p1 - 1);
996 bv.coordCache().parPos()[&text][vi.p1 - 1] =
997 Point(0, vi.y1 - text.getPar(vi.p1 - 1).descent());
1000 if (vi.p2 < pit_type(text.paragraphs().size()) - 1) {
1001 text.redoParagraph(bv, vi.p2 + 1);
1002 bv.coordCache().parPos()[&text][vi.p2 + 1] =
1003 Point(0, vi.y2 + text.getPar(vi.p2 + 1).ascent());
1006 // and grey out above (should not happen later)
1007 // lyxerr << "par ascent: " << text.getPar(vi.p1).ascent() << endl;
1008 if (vi.y1 > 0 && !vi.singlepar)
1009 pain.fillRectangle(0, 0, bv.workWidth(), vi.y1, LColor::bottomarea);
1011 // and possibly grey out below
1012 // lyxerr << "par descent: " << text.getPar(vi.p1).ascent() << endl;
1013 if (vi.y2 < bv.workHeight() && !vi.singlepar)
1014 pain.fillRectangle(0, vi.y2, bv.workWidth(), bv.workHeight() - vi.y2, LColor::bottomarea);
1018 void paintTextInset(LyXText const & text, PainterInfo & pi, int x, int y)
1020 // lyxerr << " paintTextInset: y: " << y << endl;
1022 y -= text.getPar(0).ascent();
1023 // This flag can not be set from within same inset:
1024 bool repaintAll = refreshInside;
1025 for (int pit = 0; pit < int(text.paragraphs().size()); ++pit) {
1026 y += text.getPar(pit).ascent();
1027 paintPar(pi, text, pit, x, y, repaintAll);
1028 y += text.getPar(pit).descent();