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.
15 #include "rowpainter.h"
19 #include "CoordCache.h"
21 #include "BufferParams.h"
22 #include "BufferView.h"
29 #include "MetricsInfo.h"
30 #include "Paragraph.h"
31 #include "ParagraphMetrics.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/debug.h"
42 #include "support/gettext.h"
43 #include "support/textutils.h"
45 #include "support/lassert.h"
46 #include <boost/crc.hpp>
52 using frontend::Painter;
53 using frontend::FontMetrics;
55 RowPainter::RowPainter(PainterInfo & pi,
56 Text const & text, pit_type pit, Row const & row, Bidi & bidi, int x, int y)
57 : pi_(pi), text_(text),
58 text_metrics_(pi_.base.bv->textMetrics(&text)),
59 pars_(text.paragraphs()),
60 row_(row), pit_(pit), par_(text.paragraphs()[pit]),
61 pm_(text_metrics_.parMetrics(pit)),
62 bidi_(bidi), change_(pi_.change_),
63 xo_(x), yo_(y), width_(text_metrics_.width())
65 bidi_.computeTables(par_, pi_.base.bv->buffer(), row_);
68 //lyxerr << "RowPainter: x: " << x_ << " xo: " << xo_ << " yo: " << yo_ << endl;
71 LASSERT(pit >= 0, /**/);
72 LASSERT(pit < int(text.paragraphs().size()), /**/);
76 FontInfo RowPainter::labelFont() const
78 FontInfo f = text_.labelFont(par_);
80 if (row_.begin_margin_sel || pi_.selected)
81 f.setPaintColor(Color_selectiontext);
86 int RowPainter::leftMargin() const
88 return text_metrics_.leftMargin(text_metrics_.width(), pit_,
92 // If you want to debug inset metrics uncomment the following line:
93 //#define DEBUG_METRICS
94 // This draws green lines around each inset.
97 void RowPainter::paintInset(Inset const * inset, pos_type const pos)
99 Font const font = text_metrics_.displayFont(pit_, pos);
101 LASSERT(inset, return);
102 // Backup full_repaint status because some insets (InsetTabular)
103 // requires a full repaint
104 bool pi_full_repaint = pi_.full_repaint;
106 // FIXME: text_metrics_.width() is only about 1.0857 * mi.base.textwidth
107 pi_.base.textwidth = text_metrics_.width();
109 // FIXME: We should always use font, see documentation of
110 // noFontChange() in Inset.h.
111 pi_.base.font = inset->noFontChange() ?
112 pi_.base.bv->buffer().params().getFont().fontInfo() :
114 pi_.ltr_pos = (bidi_.level(pos) % 2 == 0);
115 pi_.change_ = change_.changed() ? change_ : par_.lookupChange(pos);
117 int const x1 = int(x_);
118 pi_.base.bv->coordCache().insets().add(inset, x1, yo_);
119 // insets are painted completely. Recursive
120 inset->drawBackground(pi_, x1, yo_);
121 inset->drawSelection(pi_, x1, yo_);
122 inset->draw(pi_, x1, yo_);
124 Dimension const & dim = pm_.insetDimension(inset);
126 paintForeignMark(x_, font.language(), dim.descent());
130 // Restore full_repaint status.
131 pi_.full_repaint = pi_full_repaint;
134 int const x2 = x1 + dim.wid;
135 int const y1 = yo_ + dim.des;
136 int const y2 = yo_ - dim.asc;
137 pi_.pain.line(x1, y1, x1, y2, Color_green);
138 pi_.pain.line(x1, y1, x2, y1, Color_green);
139 pi_.pain.line(x2, y1, x2, y2, Color_green);
140 pi_.pain.line(x1, y2, x2, y2, Color_green);
145 void RowPainter::paintHebrewComposeChar(pos_type & vpos, FontInfo const & font)
147 pos_type pos = bidi_.vis2log(vpos);
152 char_type c = par_.getChar(pos);
156 int const width = theFontMetrics(font).width(c);
159 for (pos_type i = pos - 1; i >= 0; --i) {
161 if (!Encodings::isHebrewComposeChar(c)) {
162 if (isPrintableNonspace(c)) {
163 int const width2 = pm_.singleWidth(i,
164 text_metrics_.displayFont(pit_, i));
165 dx = (c == 0x05e8 || // resh
166 c == 0x05d3) // dalet
168 : (width2 - width) / 2;
175 pi_.pain.text(int(x_) + dx, yo_, str, font);
179 void RowPainter::paintArabicComposeChar(pos_type & vpos, FontInfo const & font)
181 pos_type pos = bidi_.vis2log(vpos);
185 char_type c = par_.getChar(pos);
186 c = par_.transformChar(c, pos);
190 int const width = theFontMetrics(font).width(c);
193 for (pos_type i = pos - 1; i >= 0; --i) {
195 if (!Encodings::isArabicComposeChar(c)) {
196 if (isPrintableNonspace(c)) {
197 int const width2 = pm_.singleWidth(i,
198 text_metrics_.displayFont(pit_, i));
199 dx = (width2 - width) / 2;
205 pi_.pain.text(int(x_) + dx, yo_, str, font);
209 void RowPainter::paintChars(pos_type & vpos, FontInfo const & font,
210 bool hebrew, bool arabic)
212 // This method takes up 70% of time when typing
213 pos_type pos = bidi_.vis2log(vpos);
215 vector<char_type> str;
217 str.push_back(par_.getChar(pos));
220 char_type c = str[0];
225 str[0] = par_.transformChar(c, pos);
228 pos_type const end = row_.endpos();
229 FontSpan const font_span = par_.fontSpan(pos);
230 // Track-change status.
231 Change const & change_running = par_.lookupChange(pos);
234 bool const selection = (pos >= row_.sel_beg && pos < row_.sel_end)
237 char_type prev_char = ' ';
238 // collect as much similar chars as we can
239 for (++vpos ; vpos < end ; ++vpos) {
240 pos = bidi_.vis2log(vpos);
241 if (pos < font_span.first || pos > font_span.last)
244 bool const new_selection = pos >= row_.sel_beg && pos < row_.sel_end;
245 if (new_selection != selection)
246 // Selection ends or starts here.
249 Change const & change = par_.lookupChange(pos);
250 if (!change_running.isSimilarTo(change))
251 // Track change type or author has changed.
254 char_type c = par_.getChar(pos);
256 if (c == '\t' || prev_char == '\t') {
261 if (!isPrintableNonspace(c))
264 /* Because we do our own bidi, at this point the strings are
265 * already in visual order. However, Qt also applies its own
266 * bidi algorithm to strings that it paints to the screen.
267 * Therefore, if we were to paint Hebrew/Arabic words as a
268 * single string, the letters in the words would get reversed
269 * again. In order to avoid that, we don't collect Hebrew/
270 * Arabic characters, but rather paint them one at a time.
271 * See also http://thread.gmane.org/gmane.editors.lyx.devel/79740
276 /* FIXME: these checks are irrelevant, since 'arabic' and
277 * 'hebrew' alone are already going to trigger a break.
278 * However, this should not be removed completely, because
279 * if an alternative solution is found which allows grouping
280 * of arabic and hebrew characters, then these breaks may have
283 if (arabic && Encodings::isArabicComposeChar(c))
286 if (hebrew && Encodings::isHebrewComposeChar(c))
295 c = par_.transformChar(c, pos);
296 /* see comment in hebrew, explaining why we break */
303 docstring s(&str[0], str.size());
306 s.replace(0,1,from_ascii(" "));
308 if (!selection && !change_running.changed()) {
309 x_ += pi_.pain.text(int(x_), yo_, s, font);
313 FontInfo copy = font;
314 if (change_running.changed())
315 copy.setPaintColor(change_running.color());
317 copy.setPaintColor(Color_selectiontext);
319 x_ += pi_.pain.text(int(x_), yo_, s, copy);
323 void RowPainter::paintForeignMark(double orig_x, Language const * lang,
326 if (!lyxrc.mark_foreign_language)
328 if (lang == latex_language)
330 if (lang == pi_.base.bv->buffer().params().language)
333 int const y = yo_ + 1 + desc;
334 pi_.pain.line(int(orig_x), y, int(x_), y, Color_language);
338 void RowPainter::paintMisspelledMark(double orig_x, int desc)
340 int const y = yo_ + desc;
341 pi_.pain.line(int(orig_x), y, int(x_), y, Color_red, Painter::line_onoffdash, 0.5);
345 void RowPainter::paintFromPos(pos_type & vpos)
347 pos_type const pos = bidi_.vis2log(vpos);
348 Font const orig_font = text_metrics_.displayFont(pit_, pos);
349 double const orig_x = x_;
351 // usual characters, no insets
352 char_type const c = par_.getChar(pos);
354 // special case languages
355 string const & lang = orig_font.language()->lang();
356 bool const hebrew = lang == "hebrew";
357 bool const arabic = lang == "arabic_arabtex" || lang == "arabic_arabi" ||
360 // draw as many chars as we can
361 if ((!hebrew && !arabic)
362 || (hebrew && !Encodings::isHebrewComposeChar(c))
363 || (arabic && !Encodings::isArabicComposeChar(c))) {
364 paintChars(vpos, orig_font.fontInfo(), hebrew, arabic);
366 paintHebrewComposeChar(vpos, orig_font.fontInfo());
368 paintArabicComposeChar(vpos, orig_font.fontInfo());
371 paintForeignMark(orig_x, orig_font.language());
373 if (lyxrc.spellcheck_continuously && orig_font.isMisspelled())
374 paintMisspelledMark(orig_x, 2);
378 void RowPainter::paintChangeBar()
380 pos_type const start = row_.pos();
381 pos_type end = row_.endpos();
383 if (par_.size() == end) {
384 // this is the last row of the paragraph;
385 // thus, we must also consider the imaginary end-of-par character
389 if (start == end || !par_.isChanged(start, end))
392 int const height = text_metrics_.isLastRow(pit_, row_)
396 pi_.pain.fillRectangle(5, yo_ - row_.ascent(), 3, height, Color_changebar);
400 void RowPainter::paintAppendix()
402 // only draw the appendix frame once (for the main text)
403 if (!par_.params().appendix() || !text_.isMainText())
406 int y = yo_ - row_.ascent();
408 if (par_.params().startOfAppendix())
409 y += 2 * defaultRowHeight();
411 pi_.pain.line(1, y, 1, yo_ + row_.height(), Color_appendix);
412 pi_.pain.line(width_ - 2, y, width_ - 2, yo_ + row_.height(), Color_appendix);
416 void RowPainter::paintDepthBar()
418 depth_type const depth = par_.getDepth();
423 depth_type prev_depth = 0;
424 if (!text_metrics_.isFirstRow(pit_, row_)) {
425 pit_type pit2 = pit_;
428 prev_depth = pars_[pit2].getDepth();
431 depth_type next_depth = 0;
432 if (!text_metrics_.isLastRow(pit_, row_)) {
433 pit_type pit2 = pit_;
434 if (row_.endpos() >= pars_[pit2].size())
436 next_depth = pars_[pit2].getDepth();
439 for (depth_type i = 1; i <= depth; ++i) {
440 int const w = nestMargin() / 5;
441 int x = int(xo_) + w * i;
442 // only consider the changebar space if we're drawing outermost text
443 if (text_.isMainText())
444 x += changebarMargin();
446 int const starty = yo_ - row_.ascent();
447 int const h = row_.height() - 1 - (i - next_depth - 1) * 3;
449 pi_.pain.line(x, starty, x, starty + h, Color_depthbar);
452 pi_.pain.fillRectangle(x, starty, w, 2, Color_depthbar);
454 pi_.pain.fillRectangle(x, starty + h, w, 2, Color_depthbar);
459 int RowPainter::paintAppendixStart(int y)
461 FontInfo pb_font = sane_font;
462 pb_font.setColor(Color_appendix);
469 docstring const label = _("Appendix");
470 theFontMetrics(pb_font).rectText(label, w, a, d);
472 int const text_start = int(xo_ + (width_ - w) / 2);
473 int const text_end = text_start + w;
475 pi_.pain.rectText(text_start, y + d, label, pb_font, Color_none, Color_none);
477 pi_.pain.line(int(xo_ + 1), y, text_start, y, Color_appendix);
478 pi_.pain.line(text_end, y, int(xo_ + width_ - 2), y, Color_appendix);
480 return 3 * defaultRowHeight();
484 void RowPainter::paintFirst()
486 ParagraphParameters const & pparams = par_.params();
487 Buffer const & buffer = pi_.base.bv->buffer();
488 BufferParams const & bparams = buffer.params();
489 Layout const & layout = par_.layout();
493 // start of appendix?
494 if (pparams.startOfAppendix())
495 y_top += paintAppendixStart(yo_ - row_.ascent() + 2 * defaultRowHeight());
497 if (bparams.paragraph_separation == BufferParams::ParagraphSkipSeparation
499 if (layout.latextype == LATEX_PARAGRAPH
500 && !par_.getDepth()) {
501 y_top += bparams.getDefSkip().inPixels(*pi_.base.bv);
503 Layout const & playout = pars_[pit_ - 1].layout();
504 if (playout.latextype == LATEX_PARAGRAPH
505 && !pars_[pit_ - 1].getDepth()) {
506 // is it right to use defskip here, too? (AS)
507 y_top += bparams.getDefSkip().inPixels(*pi_.base.bv);
512 bool const is_rtl = text_.isRTL(par_);
513 bool const is_seq = text_.isFirstInSequence(pit_);
514 //lyxerr << "paintFirst: " << par_.id() << " is_seq: " << is_seq << endl;
516 // should we print a label?
517 if (layout.labeltype >= LABEL_STATIC
518 && (layout.labeltype != LABEL_STATIC
519 || layout.latextype != LATEX_ENVIRONMENT
522 FontInfo const font = labelFont();
523 FontMetrics const & fm = theFontMetrics(font);
525 docstring const str = par_.labelString();
529 // this is special code for the chapter layout. This is
530 // printed in an extra row and has a pagebreak at
532 if (layout.counter == "chapter") {
533 double spacing_val = 1.0;
534 if (!pparams.spacing().isDefault()) {
535 spacing_val = pparams.spacing().getValue();
537 spacing_val = bparams.spacing().getValue();
540 int const labeladdon = int(fm.maxHeight() * layout.spacing.getValue() * spacing_val);
542 int const maxdesc = int(fm.maxDescent() * layout.spacing.getValue() * spacing_val)
543 + int(layout.parsep) * defaultRowHeight();
546 x = width_ - leftMargin() -
550 pi_.pain.text(int(x), yo_ - maxdesc - labeladdon, str, font);
553 x = width_ - leftMargin()
554 + fm.width(layout.labelsep);
556 x = x_ - fm.width(layout.labelsep)
560 pi_.pain.text(int(x), yo_, str, font);
564 // the labels at the top of an environment.
565 // More or less for bibliography
567 (layout.labeltype == LABEL_TOP_ENVIRONMENT ||
568 layout.labeltype == LABEL_BIBLIO ||
569 layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)) {
570 FontInfo const font = labelFont();
571 docstring const str = par_.labelString();
573 double spacing_val = 1.0;
574 if (!pparams.spacing().isDefault())
575 spacing_val = pparams.spacing().getValue();
577 spacing_val = bparams.spacing().getValue();
579 FontMetrics const & fm = theFontMetrics(font);
581 int const labeladdon = int(fm.maxHeight()
582 * layout.spacing.getValue() * spacing_val);
585 int(fm.maxDescent() * layout.spacing.getValue() * spacing_val
586 + (layout.labelbottomsep * defaultRowHeight()));
589 if (layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
592 x += (width_ - text_metrics_.rightMargin(pm_) - leftMargin()) / 2;
593 x -= fm.width(str) / 2;
595 x = width_ - leftMargin() - fm.width(str);
597 pi_.pain.text(int(x), yo_ - maxdesc - labeladdon, str, font);
603 /** Check if the current paragraph is the last paragraph in a
605 static int getEndLabel(pit_type p, Text const & text)
607 ParagraphList const & pars = text.paragraphs();
609 depth_type par_depth = pars[p].getDepth();
610 while (pit != pit_type(pars.size())) {
611 Layout const & layout = pars[pit].layout();
612 int const endlabeltype = layout.endlabeltype;
614 if (endlabeltype != END_LABEL_NO_LABEL) {
615 if (p + 1 == pit_type(pars.size()))
618 depth_type const next_depth =
619 pars[p + 1].getDepth();
620 if (par_depth > next_depth ||
621 (par_depth == next_depth && layout != pars[p + 1].layout()))
627 pit = text.outerHook(pit);
628 if (pit != pit_type(pars.size()))
629 par_depth = pars[pit].getDepth();
631 return END_LABEL_NO_LABEL;
635 void RowPainter::paintLast()
637 bool const is_rtl = text_.isRTL(par_);
638 int const endlabel = getEndLabel(pit_, text_);
640 // paint imaginary end-of-paragraph character
642 Change const & change = par_.lookupChange(par_.size());
643 if (change.changed()) {
644 FontMetrics const & fm =
645 theFontMetrics(pi_.base.bv->buffer().params().getFont());
646 int const length = fm.maxAscent() / 2;
647 Color col = change.color();
649 pi_.pain.line(int(x_) + 1, yo_ + 2, int(x_) + 1, yo_ + 2 - length, col,
650 Painter::line_solid, 3);
652 if (change.deleted()) {
653 pi_.pain.line(int(x_) + 1 - length, yo_ + 2, int(x_) + 1 + length,
654 yo_ + 2, col, Painter::line_solid, 3);
656 pi_.pain.line(int(x_) + 1 - length, yo_ + 2, int(x_) + 1,
657 yo_ + 2, col, Painter::line_solid, 3);
665 case END_LABEL_FILLED_BOX: {
666 FontInfo const font = labelFont();
667 FontMetrics const & fm = theFontMetrics(font);
668 int const size = int(0.75 * fm.maxAscent());
669 int const y = yo_ - size;
670 int const max_row_width = width_ - size - Inset::TEXT_TO_INSET_OFFSET;
671 int x = is_rtl ? nestMargin() + changebarMargin()
672 : max_row_width - text_metrics_.rightMargin(pm_);
674 // If needed, move the box a bit to avoid overlapping with text.
675 int const rem = max_row_width - row_.width();
677 x += is_rtl ? rem : - rem;
679 if (endlabel == END_LABEL_BOX)
680 pi_.pain.rectangle(x, y, size, size, Color_eolmarker);
682 pi_.pain.fillRectangle(x, y, size, size, Color_eolmarker);
686 case END_LABEL_STATIC: {
687 FontInfo const font = labelFont();
688 FontMetrics const & fm = theFontMetrics(font);
689 docstring const & str = par_.layout().endlabelstring();
690 double const x = is_rtl ? x_ - fm.width(str) : x_;
691 pi_.pain.text(int(x), yo_, str, font);
695 case END_LABEL_NO_LABEL:
696 if (lyxrc.paragraph_markers && size_type(pit_ + 1) < pars_.size()) {
697 docstring const s = docstring(1, char_type(0x00B6));
698 FontInfo f = FontInfo();
699 FontMetrics const & fm = theFontMetrics(f);
700 f.setColor(Color_paragraphmarker);
701 pi_.pain.text(int(x_), yo_, s, f);
709 void RowPainter::paintOnlyInsets()
711 CoordCache const & cache = pi_.base.bv->coordCache();
712 pos_type const end = row_.endpos();
713 for (pos_type pos = row_.pos(); pos != end; ++pos) {
714 // If outer row has changed, nested insets are repaint completely.
715 Inset const * inset = par_.getInset(pos);
718 if (x_ > pi_.base.bv->workWidth()
719 || !cache.getInsets().has(inset))
721 x_ = cache.getInsets().x(inset);
723 bool const pi_selected = pi_.selected;
724 Cursor const & cur = pi_.base.bv->cursor();
725 if (cur.selection() && cur.text() == &text_
726 && cur.normalAnchor().text() == &text_)
727 pi_.selected = row_.sel_beg <= pos && row_.sel_end > pos;
728 paintInset(inset, pos);
729 pi_.selected = pi_selected;
734 void RowPainter::paintText()
736 pos_type const end = row_.endpos();
737 // Spaces at logical line breaks in bidi text must be skipped during
738 // painting. However, they may appear visually in the middle
739 // of a row; they must be skipped, wherever they are...
740 // * logically "abc_[HEBREW_\nHEBREW]"
741 // * visually "abc_[_WERBEH\nWERBEH]"
742 pos_type skipped_sep_vpos = -1;
743 pos_type body_pos = par_.beginOfBody();
745 (body_pos > end || !par_.isLineSeparator(body_pos - 1))) {
749 Layout const & layout = par_.layout();
751 Change change_running;
752 int change_last_x = 0;
754 // check for possible inline completion
755 DocIterator const & inlineCompletionPos = pi_.base.bv->inlineCompletionPos();
756 pos_type inlineCompletionVPos = -1;
757 if (inlineCompletionPos.inTexted()
758 && inlineCompletionPos.text() == &text_
759 && inlineCompletionPos.pit() == pit_
760 && inlineCompletionPos.pos() - 1 >= row_.pos()
761 && inlineCompletionPos.pos() - 1 < row_.endpos()) {
762 // draw logically behind the previous character
763 inlineCompletionVPos = bidi_.log2vis(inlineCompletionPos.pos() - 1);
766 // Use font span to speed things up, see below
770 // If the last logical character is a separator, don't paint it, unless
771 // it's in the last row of a paragraph; see skipped_sep_vpos declaration
772 if (end > 0 && end < par_.size() && par_.isSeparator(end - 1))
773 skipped_sep_vpos = bidi_.log2vis(end - 1);
775 for (pos_type vpos = row_.pos(); vpos < end; ) {
776 if (x_ > pi_.base.bv->workWidth())
779 // Skip the separator at the logical end of the row
780 if (vpos == skipped_sep_vpos) {
785 pos_type const pos = bidi_.vis2log(vpos);
787 if (pos >= par_.size()) {
792 // Use font span to speed things up, see above
793 if (vpos < font_span.first || vpos > font_span.last) {
794 font_span = par_.fontSpan(vpos);
795 font = text_metrics_.displayFont(pit_, vpos);
797 // split font span if inline completion is inside
798 if (font_span.first <= inlineCompletionVPos
799 && font_span.last > inlineCompletionVPos)
800 font_span.last = inlineCompletionVPos;
803 const int width_pos = pm_.singleWidth(pos, font);
805 if (x_ + width_pos < 0) {
810 Change const & change = par_.lookupChange(pos);
811 if (change.changed() && !change_running.changed()) {
812 change_running = change;
813 change_last_x = int(x_);
816 Inset const * inset = par_.getInset(pos);
817 bool const highly_editable_inset = inset
818 && inset->editable();
820 // If we reach the end of a change or if the author changes, paint it.
821 // We also don't paint across things like tables
822 if (change_running.changed() && (highly_editable_inset
823 || !change.changed() || !change_running.isSimilarTo(change))) {
824 // Calculate 1/3 height of the buffer's default font
825 FontMetrics const & fm
826 = theFontMetrics(pi_.base.bv->buffer().params().getFont());
827 int const y_bar = change_running.deleted() ?
828 yo_ - fm.maxAscent() / 3 : yo_ + fm.maxAscent() / 6;
829 pi_.pain.line(change_last_x, y_bar, int(x_), y_bar,
830 change_running.color(), Painter::line_solid, 0.5);
832 // Change might continue with a different author or type
833 if (change.changed() && !highly_editable_inset) {
834 change_running = change;
835 change_last_x = int(x_);
837 change_running.setUnchanged();
840 if (body_pos > 0 && pos == body_pos - 1) {
841 int const lwidth = theFontMetrics(labelFont())
842 .width(layout.labelsep);
844 x_ += row_.label_hfill + lwidth - width_pos;
847 // Is the inline completion in front of character?
848 if (font.isRightToLeft() && vpos == inlineCompletionVPos)
849 paintInlineCompletion(font);
851 if (par_.isSeparator(pos)) {
852 Font const orig_font = text_metrics_.displayFont(pit_, pos);
853 double const orig_x = x_;
856 x_ += row_.separator;
857 paintForeignMark(orig_x, orig_font.language());
861 // If outer row has changed, nested insets are repaint completely.
862 pi_.base.bv->coordCache().insets().add(inset, int(x_), yo_);
864 bool const pi_selected = pi_.selected;
865 Cursor const & cur = pi_.base.bv->cursor();
866 if (cur.selection() && cur.text() == &text_
867 && cur.normalAnchor().text() == &text_)
868 pi_.selected = row_.sel_beg <= pos && row_.sel_end > pos;
869 paintInset(inset, pos);
870 pi_.selected = pi_selected;
874 // paint as many characters as possible.
878 // Is the inline completion after character?
879 if (!font.isRightToLeft() && vpos - 1 == inlineCompletionVPos)
880 paintInlineCompletion(font);
883 // if we reach the end of a struck out range, paint it
884 if (change_running.changed()) {
885 FontMetrics const & fm
886 = theFontMetrics(pi_.base.bv->buffer().params().getFont());
887 int const y_bar = change_running.deleted() ?
888 yo_ - fm.maxAscent() / 3 : yo_ + fm.maxAscent() / 6;
889 pi_.pain.line(change_last_x, y_bar, int(x_), y_bar,
890 change_running.color(), Painter::line_solid, 0.5);
891 change_running.setUnchanged();
896 void RowPainter::paintInlineCompletion(Font const & font)
898 docstring completion = pi_.base.bv->inlineCompletion();
899 FontInfo f = font.fontInfo();
900 bool rtl = font.isRightToLeft();
902 // draw the unique and the non-unique completion part
903 // Note: this is not time-critical as it is
904 // only done once per screen.
905 size_t uniqueTo = pi_.base.bv->inlineCompletionUniqueChars();
906 docstring s1 = completion.substr(0, uniqueTo);
907 docstring s2 = completion.substr(uniqueTo);
908 ColorCode c1 = Color_inlinecompletion;
909 ColorCode c2 = Color_nonunique_inlinecompletion;
919 pi_.pain.text(int(x_), yo_, s1, f);
920 x_ += theFontMetrics(font).width(s1);
925 pi_.pain.text(int(x_), yo_, s2, f);
926 x_ += theFontMetrics(font).width(s2);