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 "ParagraphMetrics.h"
31 #include "paragraph_funcs.h"
32 #include "ParagraphParameters.h"
33 #include "TextMetrics.h"
36 #include "frontends/FontMetrics.h"
37 #include "frontends/Painter.h"
39 #include "insets/insettext.h"
41 #include "support/textutils.h"
43 #include <boost/crc.hpp>
48 using frontend::Painter;
49 using frontend::FontMetrics;
58 /// Flag: do a full redraw of inside text of inset
59 /// Working variable indicating a full screen refresh
63 * A class used for painting an individual row of text.
67 /// initialise and run painter
68 RowPainter(PainterInfo & pi, LyXText const & text,
69 pit_type pit, Row const & row, int x, int y);
71 // paint various parts
74 void paintChangeBar();
78 int maxWidth() { return max_width_; }
81 void paintForeignMark(double orig_x, LyXFont const & font, int desc = 0);
82 void paintHebrewComposeChar(pos_type & vpos, LyXFont const & font);
83 void paintArabicComposeChar(pos_type & vpos, LyXFont const & font);
84 void paintChars(pos_type & vpos, LyXFont const & font,
85 bool hebrew, bool arabic);
86 int paintAppendixStart(int y);
87 void paintFromPos(pos_type & vpos);
88 void paintInset(pos_type const pos, LyXFont const & font);
90 /// return left margin
91 int leftMargin() const;
93 /// return the label font for this row
94 LyXFont const getLabelFont() const;
96 /// bufferview to paint on
102 /// LyXText for the row
103 LyXText const & text_;
104 TextMetrics & text_metrics_;
105 ParagraphList const & pars_;
112 Paragraph const & par_;
113 ParagraphMetrics const & pm_;
116 /// is row erased? (change tracking)
121 int const yo_; // current baseline
130 RowPainter::RowPainter(PainterInfo & pi,
131 LyXText const & text, pit_type pit, Row const & row, int x, int y)
132 : bv_(*pi.base.bv), pain_(pi.pain), text_(text),
133 text_metrics_(pi.base.bv->textMetrics(&text)),
134 pars_(text.paragraphs()),
135 row_(row), pit_(pit), par_(text.paragraphs()[pit]),
136 pm_(text_metrics_.parMetrics(pit)),
137 max_width_(bv_.workWidth()),
139 xo_(x), yo_(y), width_(text_metrics_.width())
141 Buffer const & buffer = *bv_.buffer();
142 int const right_margin = text_metrics_.rightMargin(pm_);
143 RowMetrics m = text_metrics_.computeRowMetrics(pit_, row_);
146 //lyxerr << "RowPainter: x: " << x_ << " xo: " << xo_ << " yo: " << yo_ << endl;
149 separator_ = m.separator;
151 label_hfill_ = m.label_hfill;
153 BOOST_ASSERT(pit >= 0);
154 BOOST_ASSERT(pit < int(text.paragraphs().size()));
158 LyXFont const RowPainter::getLabelFont() const
160 return text_.getLabelFont(*bv_.buffer(), par_);
164 int RowPainter::leftMargin() const
166 return text_.leftMargin(*bv_.buffer(), max_width_, pit_, row_.pos());
170 // If you want to debug inset metrics uncomment the following line:
171 // #define DEBUG_METRICS
172 // This draws green lines around each inset.
175 void RowPainter::paintInset(pos_type const pos, LyXFont const & font)
177 InsetBase const * inset = par_.getInset(pos);
179 PainterInfo pi(const_cast<BufferView *>(&bv_), pain_);
180 // FIXME: We should always use font, see documentation of
181 // noFontChange() in insetbase.h.
182 pi.base.font = inset->noFontChange() ?
183 bv_.buffer()->params().getFont() :
185 pi.ltr_pos = (text_.bidi.level(pos) % 2 == 0);
186 pi.erased_ = erased_ || par_.isDeleted(pos);
188 int const x1 = int(x_);
190 bv_.coordCache().insets().add(inset, int(x_), yo_);
191 InsetText const * const in = inset->asTextInset();
192 // non-wide insets are painted completely. Recursive
193 bool tmp = refreshInside;
194 if (!in || !in->wide()) {
195 refreshInside = true;
196 if (lyxerr.debugging(Debug::PAINTING)) {
197 lyxerr << endl << "Paint inset fully" << endl;
201 inset->drawSelection(pi, int(x_), yo_);
202 inset->draw(pi, int(x_), yo_);
204 x_ += inset->width();
207 BOOST_ASSERT(max_witdh_ > 0);
208 int right_margin = text_metrics_.rightMargin(pm_);
209 int const w = max_witdh_ - leftMargin() - right_margin;
210 MetricsInfo mi(&bv_, font, w);
211 inset->metrics(mi, dim);
212 if (inset->width() > dim.wid)
213 lyxerr << "Error: inset " << to_ascii(inset->getInsetName())
214 << " draw width " << inset->width()
215 << "> metrics width " << dim.wid << "." << std::endl;
216 if (inset->ascent() > dim.asc)
217 lyxerr << "Error: inset " << to_ascii(inset->getInsetName())
218 << " draw ascent " << inset->ascent()
219 << "> metrics ascent " << dim.asc << "." << std::endl;
220 if (inset->descent() > dim.des)
221 lyxerr << "Error: inset " << to_ascii(inset->getInsetName())
222 << " draw ascent " << inset->descent()
223 << "> metrics descent " << dim.des << "." << std::endl;
224 BOOST_ASSERT(inset->width() <= dim.wid);
225 BOOST_ASSERT(inset->ascent() <= dim.asc);
226 BOOST_ASSERT(inset->descent() <= dim.des);
227 int const x2 = x1 + dim.wid;
228 int const y1 = yo_ + dim.des;
229 int const y2 = yo_ - dim.asc;
230 pi.pain.line(x1, y1, x1, y2, LColor::green);
231 pi.pain.line(x1, y1, x2, y1, LColor::green);
232 pi.pain.line(x2, y1, x2, y2, LColor::green);
233 pi.pain.line(x1, y2, x2, y2, LColor::green);
238 void RowPainter::paintHebrewComposeChar(pos_type & vpos, LyXFont const & font)
240 pos_type pos = text_.bidi.vis2log(vpos);
245 char_type c = par_.getChar(pos);
249 int const width = theFontMetrics(font).width(c);
252 for (pos_type i = pos - 1; i >= 0; --i) {
254 if (!Encodings::isComposeChar_hebrew(c)) {
255 if (isPrintableNonspace(c)) {
256 int const width2 = text_.singleWidth(par_, i, c,
257 text_.getFont(*bv_.buffer(), par_, i));
259 // This does not work anymore, and non-ascii
260 // characters in source files are forbidden
263 dx = (c == 'ø' || c == 'ã')
265 : (width2 - width) / 2;
273 pain_.text(int(x_) + dx, yo_, str, font);
277 void RowPainter::paintArabicComposeChar(pos_type & vpos, LyXFont const & font)
279 pos_type pos = text_.bidi.vis2log(vpos);
283 char_type c = par_.getChar(pos);
284 c = par_.transformChar(c, pos);
288 int const width = theFontMetrics(font).width(c);
291 for (pos_type i = pos - 1; i >= 0; --i) {
293 if (!Encodings::isComposeChar_arabic(c)) {
294 if (isPrintableNonspace(c)) {
295 int const width2 = text_.singleWidth(par_, i, c,
296 text_.getFont(*bv_.buffer(), par_, i));
297 dx = (width2 - width) / 2;
303 pain_.text(int(x_) + dx, yo_, str, font);
306 void RowPainter::paintChars(pos_type & vpos, LyXFont const & font,
307 bool hebrew, bool arabic)
309 // This method takes up 70% of time when typing
310 pos_type pos = text_.bidi.vis2log(vpos);
311 pos_type const end = row_.endpos();
312 FontSpan const font_span = par_.fontSpan(pos);
313 Change::Type const prev_change = par_.lookupChange(pos).type;
316 std::vector<char_type> str;
318 str.push_back(par_.getChar(pos));
321 char_type c = str[0];
322 str[0] = par_.transformChar(c, pos);
325 // collect as much similar chars as we can
326 for (++vpos ; vpos < end ; ++vpos) {
327 pos = text_.bidi.vis2log(vpos);
328 if (pos < font_span.first || pos > font_span.last)
331 if (prev_change != par_.lookupChange(pos).type)
334 char_type c = par_.getChar(pos);
336 if (!isPrintableNonspace(c))
339 if (arabic && Encodings::isComposeChar_arabic(c))
342 if (hebrew && Encodings::isComposeChar_hebrew(c))
346 c = par_.transformChar(c, pos);
351 if (prev_change != Change::UNCHANGED) {
353 if (prev_change == Change::DELETED) {
354 copy.setColor(LColor::strikeout);
355 } else if (prev_change == Change::INSERTED) {
356 copy.setColor(LColor::newtext);
358 x_ += pain_.text(int(x_), yo_, &str[0], str.size(), copy);
360 x_ += pain_.text(int(x_), yo_, &str[0], str.size(), font);
365 void RowPainter::paintForeignMark(double orig_x, LyXFont const & font, int desc)
367 if (!lyxrc.mark_foreign_language)
369 if (font.language() == latex_language)
371 if (font.language() == bv_.buffer()->params().language)
374 int const y = yo_ + 1 + desc;
375 pain_.line(int(orig_x), y, int(x_), y, LColor::language);
379 void RowPainter::paintFromPos(pos_type & vpos)
381 pos_type const pos = text_.bidi.vis2log(vpos);
382 LyXFont orig_font = text_.getFont(*bv_.buffer(), par_, pos);
384 double const orig_x = x_;
386 if (par_.isInset(pos)) {
387 paintInset(pos, orig_font);
389 paintForeignMark(orig_x, orig_font,
390 par_.getInset(pos)->descent());
394 // usual characters, no insets
395 char_type const c = par_.getChar(pos);
397 // special case languages
398 std::string const & lang = orig_font.language()->lang();
399 bool const hebrew = lang == "hebrew";
400 bool const arabic = lang == "arabic" &&
401 (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
402 lyxrc.font_norm_type == LyXRC::ISO_10646_1);
404 // draw as many chars as we can
405 if ((!hebrew && !arabic)
406 || (hebrew && !Encodings::isComposeChar_hebrew(c))
407 || (arabic && !Encodings::isComposeChar_arabic(c))) {
408 paintChars(vpos, orig_font, hebrew, arabic);
410 paintHebrewComposeChar(vpos, orig_font);
412 paintArabicComposeChar(vpos, orig_font);
415 paintForeignMark(orig_x, orig_font);
419 void RowPainter::paintChangeBar()
421 pos_type const start = row_.pos();
422 pos_type end = row_.endpos();
424 if (par_.size() == end) {
425 // this is the last row of the paragraph;
426 // thus, we must also consider the imaginary end-of-par character
430 if (start == end || !par_.isChanged(start, end))
433 int const height = text_.isLastRow(pit_, row_)
437 pain_.fillRectangle(5, yo_ - row_.ascent(), 3, height, LColor::changebar);
441 void RowPainter::paintAppendix()
443 if (!par_.params().appendix())
446 int y = yo_ - row_.ascent();
448 if (par_.params().startOfAppendix())
449 y += 2 * defaultRowHeight();
451 pain_.line(1, y, 1, yo_ + row_.height(), LColor::appendix);
452 pain_.line(width_ - 2, y, width_ - 2, yo_ + row_.height(), LColor::appendix);
456 void RowPainter::paintDepthBar()
458 depth_type const depth = par_.getDepth();
463 depth_type prev_depth = 0;
464 if (!text_.isFirstRow(pit_, row_)) {
465 pit_type pit2 = pit_;
468 prev_depth = pars_[pit2].getDepth();
471 depth_type next_depth = 0;
472 if (!text_.isLastRow(pit_, row_)) {
473 pit_type pit2 = pit_;
474 if (row_.endpos() >= pars_[pit2].size())
476 next_depth = pars_[pit2].getDepth();
479 for (depth_type i = 1; i <= depth; ++i) {
480 int const w = nestMargin() / 5;
481 int x = int(xo_) + w * i;
482 // only consider the changebar space if we're drawing outermost text
483 if (text_.isMainText(*bv_.buffer()))
484 x += changebarMargin();
486 int const starty = yo_ - row_.ascent();
487 int const h = row_.height() - 1 - (i - next_depth - 1) * 3;
489 pain_.line(x, starty, x, starty + h, LColor::depthbar);
492 pain_.fillRectangle(x, starty, w, 2, LColor::depthbar);
494 pain_.fillRectangle(x, starty + h, w, 2, LColor::depthbar);
499 int RowPainter::paintAppendixStart(int y)
502 pb_font.setColor(LColor::appendix);
509 docstring const label = _("Appendix");
510 theFontMetrics(pb_font).rectText(label, w, a, d);
512 int const text_start = int(xo_ + (width_ - w) / 2);
513 int const text_end = text_start + w;
515 pain_.rectText(text_start, y + d, label, pb_font, LColor::none, LColor::none);
517 pain_.line(int(xo_ + 1), y, text_start, y, LColor::appendix);
518 pain_.line(text_end, y, int(xo_ + width_ - 2), y, LColor::appendix);
520 return 3 * defaultRowHeight();
524 void RowPainter::paintFirst()
526 ParagraphParameters const & parparams = par_.params();
530 // start of appendix?
531 if (parparams.startOfAppendix())
532 y_top += paintAppendixStart(yo_ - row_.ascent() + 2 * defaultRowHeight());
534 Buffer const & buffer = *bv_.buffer();
536 LyXLayout_ptr const & layout = par_.layout();
538 if (buffer.params().paragraph_separation == BufferParams::PARSEP_SKIP) {
540 if (layout->latextype == LATEX_PARAGRAPH
541 && !par_.getDepth()) {
542 y_top += buffer.params().getDefSkip().inPixels(bv_);
544 LyXLayout_ptr const & playout = pars_[pit_ - 1].layout();
545 if (playout->latextype == LATEX_PARAGRAPH
546 && !pars_[pit_ - 1].getDepth()) {
547 // is it right to use defskip here, too? (AS)
548 y_top += buffer.params().getDefSkip().inPixels(bv_);
554 bool const is_rtl = text_.isRTL(buffer, par_);
555 bool const is_seq = isFirstInSequence(pit_, text_.paragraphs());
556 //lyxerr << "paintFirst: " << par_.id() << " is_seq: " << is_seq << std::endl;
558 // should we print a label?
559 if (layout->labeltype >= LABEL_STATIC
560 && (layout->labeltype != LABEL_STATIC
561 || layout->latextype != LATEX_ENVIRONMENT
564 LyXFont const font = getLabelFont();
565 FontMetrics const & fm = theFontMetrics(font);
567 docstring const str = par_.getLabelstring();
571 // this is special code for the chapter layout. This is
572 // printed in an extra row and has a pagebreak at
574 if (layout->counter == "chapter") {
575 double spacing_val = 1.0;
576 if (!parparams.spacing().isDefault()) {
577 spacing_val = parparams.spacing().getValue();
579 spacing_val = buffer.params().spacing().getValue();
582 int const labeladdon = int(fm.maxHeight() * layout->spacing.getValue() * spacing_val);
584 int const maxdesc = int(fm.maxDescent() * layout->spacing.getValue() * spacing_val)
585 + int(layout->parsep) * defaultRowHeight();
588 x = width_ - leftMargin() -
592 pain_.text(int(x), yo_ - maxdesc - labeladdon, str, font);
595 docstring lab = from_utf8(layout->labelsep);
597 x = width_ - leftMargin()
600 x = x_ - fm.width(lab)
604 pain_.text(int(x), yo_, str, font);
608 // the labels at the top of an environment.
609 // More or less for bibliography
611 (layout->labeltype == LABEL_TOP_ENVIRONMENT ||
612 layout->labeltype == LABEL_BIBLIO ||
613 layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)) {
614 LyXFont font = getLabelFont();
615 if (!par_.getLabelstring().empty()) {
616 docstring const str = par_.getLabelstring();
617 double spacing_val = 1.0;
618 if (!parparams.spacing().isDefault())
619 spacing_val = parparams.spacing().getValue();
621 spacing_val = buffer.params().spacing().getValue();
623 FontMetrics const & fm = theFontMetrics(font);
625 int const labeladdon = int(fm.maxHeight()
626 * layout->spacing.getValue() * spacing_val);
629 int(fm.maxDescent() * layout->spacing.getValue() * spacing_val
630 + (layout->labelbottomsep * defaultRowHeight()));
633 if (layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
636 x += (width_ - text_metrics_.rightMargin(pm_) - leftMargin()) / 2;
637 x -= fm.width(str) / 2;
639 x = width_ - leftMargin() - fm.width(str);
641 pain_.text(int(x), yo_ - maxdesc - labeladdon, str, font);
647 void RowPainter::paintLast()
649 bool const is_rtl = text_.isRTL(*bv_.buffer(), par_);
650 int const endlabel = getEndLabel(pit_, text_.paragraphs());
652 // paint imaginary end-of-paragraph character
654 if (par_.isInserted(par_.size()) || par_.isDeleted(par_.size())) {
655 FontMetrics const & fm = theFontMetrics(bv_.buffer()->params().getFont());
656 int const length = fm.maxAscent() / 2;
657 LColor::color col = par_.isInserted(par_.size()) ? LColor::newtext : LColor::strikeout;
659 pain_.line(int(x_) + 1, yo_ + 2, int(x_) + 1, yo_ + 2 - length, col,
660 Painter::line_solid, Painter::line_thick);
661 pain_.line(int(x_) + 1 - length, yo_ + 2, int(x_) + 1, yo_ + 2, col,
662 Painter::line_solid, Painter::line_thick);
669 case END_LABEL_FILLED_BOX: {
670 LyXFont const font = getLabelFont();
671 FontMetrics const & fm = theFontMetrics(font);
672 int const size = int(0.75 * fm.maxAscent());
673 int const y = yo_ - size;
674 int x = is_rtl ? nestMargin() + changebarMargin() : width_ - size;
676 if (width_ - int(row_.width()) <= size)
677 x += (size - width_ + row_.width() + 1) * (is_rtl ? -1 : 1);
679 if (endlabel == END_LABEL_BOX)
680 pain_.rectangle(x, y, size, size, LColor::eolmarker);
682 pain_.fillRectangle(x, y, size, size, LColor::eolmarker);
686 case END_LABEL_STATIC: {
687 LyXFont font = getLabelFont();
688 FontMetrics const & fm = theFontMetrics(font);
689 docstring const & str = par_.layout()->endlabelstring();
690 double const x = is_rtl ?
692 : - text_metrics_.rightMargin(pm_) - row_.width();
693 pain_.text(int(x), yo_, str, font);
697 case END_LABEL_NO_LABEL:
703 void RowPainter::paintText()
705 pos_type const end = row_.endpos();
706 pos_type body_pos = par_.beginOfBody();
708 (body_pos > end || !par_.isLineSeparator(body_pos - 1))) {
712 LyXLayout_ptr const & layout = par_.layout();
714 bool running_strikeout = false;
715 bool is_struckout = false;
716 int last_strikeout_x = 0;
718 // Use font span to speed things up, see below
721 Buffer const & buffer = *bv_.buffer();
723 for (pos_type vpos = row_.pos(); vpos < end; ) {
724 if (x_ > bv_.workWidth())
727 pos_type const pos = text_.bidi.vis2log(vpos);
729 if (pos >= par_.size()) {
734 // Use font span to speed things up, see above
735 if (vpos < font_span.first || vpos > font_span.last) {
736 font_span = par_.fontSpan(vpos);
737 font = text_.getFont(buffer, par_, vpos);
740 const int width_pos =
741 text_.singleWidth(par_, pos, par_.getChar(pos), font);
743 if (x_ + width_pos < 0) {
749 is_struckout = par_.isDeleted(pos);
751 if (is_struckout && !running_strikeout) {
752 running_strikeout = true;
753 last_strikeout_x = int(x_);
756 bool const highly_editable_inset = par_.isInset(pos)
757 && isHighlyEditableInset(par_.getInset(pos));
759 // If we reach the end of a struck out range, paint it.
760 // We also don't paint across things like tables
761 if (running_strikeout && (highly_editable_inset || !is_struckout)) {
762 // Calculate 1/3 height of the buffer's default font
763 FontMetrics const & fm
764 = theFontMetrics(bv_.buffer()->params().getFont());
765 int const middle = yo_ - fm.maxAscent() / 3;
766 pain_.line(last_strikeout_x, middle, int(x_), middle,
767 LColor::strikeout, Painter::line_solid, Painter::line_thin);
768 running_strikeout = false;
771 if (body_pos > 0 && pos == body_pos - 1) {
773 int const lwidth = theFontMetrics(getLabelFont())
774 .width(from_utf8(layout->labelsep));
776 x_ += label_hfill_ + lwidth - width_pos;
779 if (par_.isHfill(pos)) {
783 int const y1 = y0 - defaultRowHeight() / 2;
785 pain_.line(int(x_), y1, int(x_), y0, LColor::added_space);
787 if (par_.hfillExpansion(row_, pos)) {
788 int const y2 = (y0 + y1) / 2;
790 if (pos >= body_pos) {
791 pain_.line(int(x_), y2, int(x_ + hfill_), y2,
793 Painter::line_onoffdash);
796 pain_.line(int(x_), y2, int(x_ + label_hfill_), y2,
798 Painter::line_onoffdash);
801 pain_.line(int(x_), y1, int(x_), y0, LColor::added_space);
805 } else if (par_.isSeparator(pos)) {
815 // if we reach the end of a struck out range, paint it
816 if (running_strikeout) {
817 // calculate 1/3 height of the buffer's default font
818 FontMetrics const & fm
819 = theFontMetrics(bv_.buffer()->params().getFont());
820 int const middle = yo_ - fm.maxAscent() / 3;
821 pain_.line(last_strikeout_x, middle, int(x_), middle,
822 LColor::strikeout, Painter::line_solid, Painter::line_thin);
823 running_strikeout = false;
828 size_type calculateRowSignature(Row const & row, Paragraph const & par,
831 boost::crc_32_type crc;
832 for (pos_type i = row.pos(); i < row.endpos(); ++i) {
833 char_type const b[] = { par.getChar(i) };
834 crc.process_bytes(b, 1);
836 char_type const b[] = { x, y, row.width() };
837 crc.process_bytes(b, 3);
838 return crc.checksum();
842 bool CursorOnRow(PainterInfo & pi, pit_type const pit,
843 RowList::const_iterator rit, LyXText const & text)
845 // Is there a cursor on this row (or inside inset on row)
846 LCursor & cur = pi.base.bv->cursor();
847 for (size_type d = 0; d < cur.depth(); ++d) {
848 CursorSlice const & sl = cur[d];
849 if (sl.text() == &text
851 && sl.pos() >= rit->pos()
852 && sl.pos() <= rit->endpos())
859 bool innerCursorOnRow(PainterInfo & pi, pit_type pit,
860 RowList::const_iterator rit, LyXText const & text)
862 // Is there a cursor inside an inset on this row, and is this inset
863 // the only "character" on this row
864 LCursor & cur = pi.base.bv->cursor();
865 if (rit->pos() + 1 != rit->endpos())
867 for (size_type d = 0; d < cur.depth(); d++) {
868 CursorSlice const & sl = cur[d];
869 if (sl.text() == &text
871 && sl.pos() == rit->pos())
872 return d < cur.depth() - 1;
879 (PainterInfo & pi, LyXText const & text, pit_type pit, int x, int y,
882 // lyxerr << " paintPar: pit: " << pit << " at y: " << y << endl;
883 int const ww = pi.base.bv->workHeight();
885 pi.base.bv->coordCache().parPos()[&text][pit] = Point(x, y);
887 Paragraph const & par = text.paragraphs()[pit];
888 ParagraphMetrics const & pm = pi.base.bv->parMetrics(&text, pit);
889 if (pm.rows().empty())
892 RowList::const_iterator const rb = pm.rows().begin();
893 RowList::const_iterator const re = pm.rows().end();
897 for (RowList::const_iterator rit = rb; rit != re; ++rit, ++rowno) {
899 // Allow setting of refreshInside for nested insets in
901 bool tmp = refreshInside;
903 // Row signature; has row changed since last paint?
904 size_type const row_sig = calculateRowSignature(*rit, par, x, y);
905 bool row_has_changed = pm.rowSignature()[rowno] != row_sig;
907 bool cursor_on_row = CursorOnRow(pi, pit, rit, text);
908 bool in_inset_alone_on_row = innerCursorOnRow(pi, pit, rit,
911 (par.getAlign() == LYX_ALIGN_LEFT ||
912 par.getAlign() == LYX_ALIGN_BLOCK);
914 // If this is the only object on the row, we can make it wide
916 // FIXME: there is a const_cast here because paintPar() is not supposed
917 // to touch the paragraph contents. So either we move this "wide"
918 // property out of InsetText or we localize the feature to the painting
920 for (pos_type i = rit->pos() ; i != rit->endpos(); ++i) {
921 InsetBase const * const in = par.getInset(i);
923 InsetText * t = const_cast<InsetText *>(in->asTextInset());
925 t->setWide(in_inset_alone_on_row && leftEdgeFixed);
929 // If selection is on, the current row signature differs
930 // from cache, or cursor is inside an inset _on this row_,
931 // then paint the row
932 if (repaintAll || row_has_changed || cursor_on_row) {
933 // Add to row signature cache
934 pm.rowSignature()[rowno] = row_sig;
936 bool const inside = (y + rit->descent() >= 0
937 && y - rit->ascent() < ww);
938 // it is not needed to draw on screen if we are not inside.
939 pi.pain.setDrawingEnabled(inside);
940 RowPainter rp(pi, text, pit, *rit, x, y);
941 // Clear background of this row
942 // (if paragraph background was not cleared)
944 (!(in_inset_alone_on_row && leftEdgeFixed)
945 || row_has_changed)) {
946 pi.pain.fillRectangle(x, y - rit->ascent(),
947 rp.maxWidth(), rit->height(),
948 text.backgroundColor());
949 // If outer row has changed, force nested
950 // insets to repaint completely
952 refreshInside = true;
955 // Instrumentation for testing row cache (see also
957 if (lyxerr.debugging(Debug::PAINTING)) {
958 if (text.isMainText(*pi.base.bv->buffer()))
959 lyxerr[Debug::PAINTING] << "#";
961 lyxerr[Debug::PAINTING] << "[" <<
962 repaintAll << row_has_changed <<
963 cursor_on_row << "]";
975 // Restore, see above
978 // Re-enable screen drawing for future use of the painter.
979 pi.pain.setDrawingEnabled(true);
981 if (lyxerr.debugging(Debug::PAINTING)) {
982 lyxerr[Debug::PAINTING] << "." << endl;
989 void paintText(BufferView & bv,
992 BOOST_ASSERT(bv.buffer());
993 Buffer const & buffer = *bv.buffer();
994 LyXText & text = buffer.text();
995 bool const select = bv.cursor().selection();
996 ViewMetricsInfo const & vi = bv.viewMetricsInfo();
998 PainterInfo pi(const_cast<BufferView *>(&bv), pain);
999 // Should the whole screen, including insets, be refreshed?
1000 bool repaintAll = select || !vi.singlepar;
1003 // Clear background (if not delegated to rows)
1004 pain.fillRectangle(0, vi.y1, bv.workWidth(), vi.y2 - vi.y1,
1005 text.backgroundColor());
1008 text.drawSelection(pi, 0, 0);
1013 for (pit_type pit = vi.p1; pit <= vi.p2; ++pit) {
1014 refreshInside = repaintAll;
1015 ParagraphMetrics const & pm = bv.parMetrics(&text, pit);
1017 paintPar(pi, text, pit, 0, yy, repaintAll);
1021 // and grey out above (should not happen later)
1022 // lyxerr << "par ascent: " << text.getPar(vi.p1).ascent() << endl;
1023 if (vi.y1 > 0 && !vi.singlepar)
1024 pain.fillRectangle(0, 0, bv.workWidth(), vi.y1, LColor::bottomarea);
1026 // and possibly grey out below
1027 // lyxerr << "par descent: " << text.getPar(vi.p1).ascent() << endl;
1028 if (vi.y2 < bv.workHeight() && !vi.singlepar)
1029 pain.fillRectangle(0, vi.y2, bv.workWidth(), bv.workHeight() - vi.y2, LColor::bottomarea);
1033 void paintTextInset(LyXText const & text, PainterInfo & pi, int x, int y)
1035 // lyxerr << " paintTextInset: y: " << y << endl;
1037 y -= pi.base.bv->parMetrics(&text, 0).ascent();
1038 // This flag cannot be set from within same inset:
1039 bool repaintAll = refreshInside;
1040 for (int pit = 0; pit < int(text.paragraphs().size()); ++pit) {
1041 ParagraphMetrics const & pmi
1042 = pi.base.bv->parMetrics(&text, pit);
1044 paintPar(pi, text, pit, x, y, repaintAll);