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: We should always use font, see documentation of
107 // noFontChange() in Inset.h.
108 pi_.base.font = inset->noFontChange() ?
109 pi_.base.bv->buffer().params().getFont().fontInfo() :
111 pi_.ltr_pos = (bidi_.level(pos) % 2 == 0);
112 pi_.change_ = change_.changed() ? change_ : par_.lookupChange(pos);
114 int const x1 = int(x_);
115 pi_.base.bv->coordCache().insets().add(inset, x1, yo_);
116 // insets are painted completely. Recursive
117 inset->drawBackground(pi_, x1, yo_);
118 inset->drawSelection(pi_, x1, yo_);
119 inset->draw(pi_, x1, yo_);
121 Dimension const & dim = pm_.insetDimension(inset);
123 paintForeignMark(x_, font.language(), dim.descent());
127 // Restore full_repaint status.
128 pi_.full_repaint = pi_full_repaint;
131 int const x2 = x1 + dim.wid;
132 int const y1 = yo_ + dim.des;
133 int const y2 = yo_ - dim.asc;
134 pi_.pain.line(x1, y1, x1, y2, Color_green);
135 pi_.pain.line(x1, y1, x2, y1, Color_green);
136 pi_.pain.line(x2, y1, x2, y2, Color_green);
137 pi_.pain.line(x1, y2, x2, y2, Color_green);
142 void RowPainter::paintHebrewComposeChar(pos_type & vpos, FontInfo const & font)
144 pos_type pos = bidi_.vis2log(vpos);
149 char_type c = par_.getChar(pos);
153 int const width = theFontMetrics(font).width(c);
156 for (pos_type i = pos - 1; i >= 0; --i) {
158 if (!Encodings::isHebrewComposeChar(c)) {
159 if (isPrintableNonspace(c)) {
160 int const width2 = pm_.singleWidth(i,
161 text_metrics_.displayFont(pit_, i));
162 dx = (c == 0x05e8 || // resh
163 c == 0x05d3) // dalet
165 : (width2 - width) / 2;
172 pi_.pain.text(int(x_) + dx, yo_, str, font);
176 void RowPainter::paintArabicComposeChar(pos_type & vpos, FontInfo const & font)
178 pos_type pos = bidi_.vis2log(vpos);
182 char_type c = par_.getChar(pos);
183 c = par_.transformChar(c, pos);
187 int const width = theFontMetrics(font).width(c);
190 for (pos_type i = pos - 1; i >= 0; --i) {
192 if (!Encodings::isArabicComposeChar(c)) {
193 if (isPrintableNonspace(c)) {
194 int const width2 = pm_.singleWidth(i,
195 text_metrics_.displayFont(pit_, i));
196 dx = (width2 - width) / 2;
202 pi_.pain.text(int(x_) + dx, yo_, str, font);
206 void RowPainter::paintChars(pos_type & vpos, FontInfo const & font,
207 bool hebrew, bool arabic)
209 // This method takes up 70% of time when typing
210 pos_type pos = bidi_.vis2log(vpos);
212 vector<char_type> str;
214 str.push_back(par_.getChar(pos));
217 char_type c = str[0];
222 str[0] = par_.transformChar(c, pos);
225 pos_type const end = row_.endpos();
226 FontSpan const font_span = par_.fontSpan(pos);
227 // Track-change status.
228 Change const & change_running = par_.lookupChange(pos);
231 bool const selection = (pos >= row_.sel_beg && pos < row_.sel_end)
235 bool const spell_state =
236 lyxrc.spellcheck_continuously && par_.isMisspelled(pos);
238 char_type prev_char = ' ';
239 // collect as much similar chars as we can
240 for (++vpos ; vpos < end ; ++vpos) {
241 pos = bidi_.vis2log(vpos);
242 if (pos < font_span.first || pos > font_span.last)
245 bool const new_selection = pos >= row_.sel_beg && pos < row_.sel_end;
246 if (new_selection != selection)
247 // Selection ends or starts here.
250 bool const new_spell_state =
251 lyxrc.spellcheck_continuously && par_.isMisspelled(pos);
252 if (new_spell_state != spell_state)
253 // Spell checker state changed here.
256 Change const & change = par_.lookupChange(pos);
257 if (!change_running.isSimilarTo(change))
258 // Track change type or author has changed.
261 char_type c = par_.getChar(pos);
263 if (c == '\t' || prev_char == '\t') {
268 if (!isPrintableNonspace(c))
271 /* Because we do our own bidi, at this point the strings are
272 * already in visual order. However, Qt also applies its own
273 * bidi algorithm to strings that it paints to the screen.
274 * Therefore, if we were to paint Hebrew/Arabic words as a
275 * single string, the letters in the words would get reversed
276 * again. In order to avoid that, we don't collect Hebrew/
277 * Arabic characters, but rather paint them one at a time.
278 * See also http://thread.gmane.org/gmane.editors.lyx.devel/79740
283 /* FIXME: these checks are irrelevant, since 'arabic' and
284 * 'hebrew' alone are already going to trigger a break.
285 * However, this should not be removed completely, because
286 * if an alternative solution is found which allows grouping
287 * of arabic and hebrew characters, then these breaks may have
290 if (arabic && Encodings::isArabicComposeChar(c))
293 if (hebrew && Encodings::isHebrewComposeChar(c))
302 c = par_.transformChar(c, pos);
303 /* see comment in hebrew, explaining why we break */
310 docstring s(&str[0], str.size());
313 s.replace(0,1,from_ascii(" "));
315 if (!selection && !change_running.changed()) {
316 x_ += pi_.pain.text(int(x_), yo_, s, font);
320 FontInfo copy = font;
321 if (change_running.changed())
322 copy.setPaintColor(change_running.color());
324 copy.setPaintColor(Color_selectiontext);
326 x_ += pi_.pain.text(int(x_), yo_, s, copy);
330 void RowPainter::paintForeignMark(double orig_x, Language const * lang,
333 if (!lyxrc.mark_foreign_language)
335 if (lang == latex_language)
337 if (lang == pi_.base.bv->buffer().params().language)
340 int const y = yo_ + 1 + desc;
341 pi_.pain.line(int(orig_x), y, int(x_), y, Color_language);
345 void RowPainter::paintMisspelledMark(double orig_x, int desc, bool changed)
347 // derive the offset from zoom factor specified by user in percent
348 // if changed the misspelled marker gets placed slightly lower than normal
349 // to avoid drawing at the same vertical offset
350 int const offset = int(1.5 * lyxrc.zoom / 100.0); // [percent]
351 int const y = yo_ + desc + (changed ? offset : 0);
352 pi_.pain.line(int(orig_x), y, int(x_), y, Color_red, Painter::line_onoffdash, 1.0);
356 void RowPainter::paintFromPos(pos_type & vpos, bool changed)
358 pos_type const pos = bidi_.vis2log(vpos);
359 Font const orig_font = text_metrics_.displayFont(pit_, pos);
360 double const orig_x = x_;
362 // usual characters, no insets
363 char_type const c = par_.getChar(pos);
365 // special case languages
366 string const & lang = orig_font.language()->lang();
367 bool const hebrew = lang == "hebrew";
368 bool const arabic = lang == "arabic_arabtex" || lang == "arabic_arabi" ||
372 bool const misspelled_ =
373 lyxrc.spellcheck_continuously && par_.isMisspelled(pos);
375 // draw as many chars as we can
376 if ((!hebrew && !arabic)
377 || (hebrew && !Encodings::isHebrewComposeChar(c))
378 || (arabic && !Encodings::isArabicComposeChar(c))) {
379 paintChars(vpos, orig_font.fontInfo(), hebrew, arabic);
381 paintHebrewComposeChar(vpos, orig_font.fontInfo());
383 paintArabicComposeChar(vpos, orig_font.fontInfo());
386 paintForeignMark(orig_x, orig_font.language());
388 if (lyxrc.spellcheck_continuously && misspelled_) {
389 paintMisspelledMark(orig_x, 2, changed);
394 void RowPainter::paintChangeBar()
396 pos_type const start = row_.pos();
397 pos_type end = row_.endpos();
399 if (par_.size() == end) {
400 // this is the last row of the paragraph;
401 // thus, we must also consider the imaginary end-of-par character
405 if (start == end || !par_.isChanged(start, end))
408 int const height = text_metrics_.isLastRow(pit_, row_)
412 pi_.pain.fillRectangle(5, yo_ - row_.ascent(), 3, height, Color_changebar);
416 void RowPainter::paintAppendix()
418 // only draw the appendix frame once (for the main text)
419 if (!par_.params().appendix() || !text_.isMainText())
422 int y = yo_ - row_.ascent();
424 if (par_.params().startOfAppendix())
425 y += 2 * defaultRowHeight();
427 pi_.pain.line(1, y, 1, yo_ + row_.height(), Color_appendix);
428 pi_.pain.line(width_ - 2, y, width_ - 2, yo_ + row_.height(), Color_appendix);
432 void RowPainter::paintDepthBar()
434 depth_type const depth = par_.getDepth();
439 depth_type prev_depth = 0;
440 if (!text_metrics_.isFirstRow(pit_, row_)) {
441 pit_type pit2 = pit_;
444 prev_depth = pars_[pit2].getDepth();
447 depth_type next_depth = 0;
448 if (!text_metrics_.isLastRow(pit_, row_)) {
449 pit_type pit2 = pit_;
450 if (row_.endpos() >= pars_[pit2].size())
452 next_depth = pars_[pit2].getDepth();
455 for (depth_type i = 1; i <= depth; ++i) {
456 int const w = nestMargin() / 5;
457 int x = int(xo_) + w * i;
458 // only consider the changebar space if we're drawing outermost text
459 if (text_.isMainText())
460 x += changebarMargin();
462 int const starty = yo_ - row_.ascent();
463 int const h = row_.height() - 1 - (i - next_depth - 1) * 3;
465 pi_.pain.line(x, starty, x, starty + h, Color_depthbar);
468 pi_.pain.fillRectangle(x, starty, w, 2, Color_depthbar);
470 pi_.pain.fillRectangle(x, starty + h, w, 2, Color_depthbar);
475 int RowPainter::paintAppendixStart(int y)
477 FontInfo pb_font = sane_font;
478 pb_font.setColor(Color_appendix);
485 docstring const label = _("Appendix");
486 theFontMetrics(pb_font).rectText(label, w, a, d);
488 int const text_start = int(xo_ + (width_ - w) / 2);
489 int const text_end = text_start + w;
491 pi_.pain.rectText(text_start, y + d, label, pb_font, Color_none, Color_none);
493 pi_.pain.line(int(xo_ + 1), y, text_start, y, Color_appendix);
494 pi_.pain.line(text_end, y, int(xo_ + width_ - 2), y, Color_appendix);
496 return 3 * defaultRowHeight();
500 void RowPainter::paintFirst()
502 ParagraphParameters const & pparams = par_.params();
503 Buffer const & buffer = pi_.base.bv->buffer();
504 BufferParams const & bparams = buffer.params();
505 Layout const & layout = par_.layout();
509 // start of appendix?
510 if (pparams.startOfAppendix())
511 y_top += paintAppendixStart(yo_ - row_.ascent() + 2 * defaultRowHeight());
513 if (bparams.paragraph_separation == BufferParams::ParagraphSkipSeparation
515 if (layout.latextype == LATEX_PARAGRAPH
516 && !par_.getDepth()) {
517 y_top += bparams.getDefSkip().inPixels(*pi_.base.bv);
519 Layout const & playout = pars_[pit_ - 1].layout();
520 if (playout.latextype == LATEX_PARAGRAPH
521 && !pars_[pit_ - 1].getDepth()) {
522 // is it right to use defskip here, too? (AS)
523 y_top += bparams.getDefSkip().inPixels(*pi_.base.bv);
528 bool const is_rtl = text_.isRTL(par_);
529 bool const is_seq = text_.isFirstInSequence(pit_);
530 //lyxerr << "paintFirst: " << par_.id() << " is_seq: " << is_seq << endl;
532 // should we print a label?
533 if (layout.labeltype >= LABEL_STATIC
534 && (layout.labeltype != LABEL_STATIC
535 || layout.latextype != LATEX_ENVIRONMENT
538 FontInfo const font = labelFont();
539 FontMetrics const & fm = theFontMetrics(font);
541 docstring const str = par_.labelString();
545 // this is special code for the chapter layout. This is
546 // printed in an extra row and has a pagebreak at
548 if (layout.counter == "chapter") {
549 double spacing_val = 1.0;
550 if (!pparams.spacing().isDefault()) {
551 spacing_val = pparams.spacing().getValue();
553 spacing_val = bparams.spacing().getValue();
556 int const labeladdon = int(fm.maxHeight() * layout.spacing.getValue() * spacing_val);
558 int const maxdesc = int(fm.maxDescent() * layout.spacing.getValue() * spacing_val)
559 + int(layout.parsep) * defaultRowHeight();
562 x = width_ - leftMargin() -
566 pi_.pain.text(int(x), yo_ - maxdesc - labeladdon, str, font);
569 x = width_ - leftMargin()
570 + fm.width(layout.labelsep);
572 x = x_ - fm.width(layout.labelsep)
576 pi_.pain.text(int(x), yo_, str, font);
580 // the labels at the top of an environment.
581 // More or less for bibliography
583 (layout.labeltype == LABEL_TOP_ENVIRONMENT ||
584 layout.labeltype == LABEL_BIBLIO ||
585 layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)) {
586 FontInfo const font = labelFont();
587 docstring const str = par_.labelString();
589 double spacing_val = 1.0;
590 if (!pparams.spacing().isDefault())
591 spacing_val = pparams.spacing().getValue();
593 spacing_val = bparams.spacing().getValue();
595 FontMetrics const & fm = theFontMetrics(font);
597 int const labeladdon = int(fm.maxHeight()
598 * layout.spacing.getValue() * spacing_val);
601 int(fm.maxDescent() * layout.spacing.getValue() * spacing_val
602 + (layout.labelbottomsep * defaultRowHeight()));
605 if (layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
608 x += (width_ - text_metrics_.rightMargin(pm_) - leftMargin()) / 2;
609 x -= fm.width(str) / 2;
611 x = width_ - leftMargin() - fm.width(str);
613 pi_.pain.text(int(x), yo_ - maxdesc - labeladdon, str, font);
619 /** Check if the current paragraph is the last paragraph in a
621 static int getEndLabel(pit_type p, Text const & text)
623 ParagraphList const & pars = text.paragraphs();
625 depth_type par_depth = pars[p].getDepth();
626 while (pit != pit_type(pars.size())) {
627 Layout const & layout = pars[pit].layout();
628 int const endlabeltype = layout.endlabeltype;
630 if (endlabeltype != END_LABEL_NO_LABEL) {
631 if (p + 1 == pit_type(pars.size()))
634 depth_type const next_depth =
635 pars[p + 1].getDepth();
636 if (par_depth > next_depth ||
637 (par_depth == next_depth && layout != pars[p + 1].layout()))
643 pit = text.outerHook(pit);
644 if (pit != pit_type(pars.size()))
645 par_depth = pars[pit].getDepth();
647 return END_LABEL_NO_LABEL;
651 void RowPainter::paintLast()
653 bool const is_rtl = text_.isRTL(par_);
654 int const endlabel = getEndLabel(pit_, text_);
656 // paint imaginary end-of-paragraph character
658 Change const & change = par_.lookupChange(par_.size());
659 if (change.changed()) {
660 FontMetrics const & fm =
661 theFontMetrics(pi_.base.bv->buffer().params().getFont());
662 int const length = fm.maxAscent() / 2;
663 Color col = change.color();
665 pi_.pain.line(int(x_) + 1, yo_ + 2, int(x_) + 1, yo_ + 2 - length, col,
666 Painter::line_solid, 3);
668 if (change.deleted()) {
669 pi_.pain.line(int(x_) + 1 - length, yo_ + 2, int(x_) + 1 + length,
670 yo_ + 2, col, Painter::line_solid, 3);
672 pi_.pain.line(int(x_) + 1 - length, yo_ + 2, int(x_) + 1,
673 yo_ + 2, col, Painter::line_solid, 3);
681 case END_LABEL_FILLED_BOX: {
682 FontInfo const font = labelFont();
683 FontMetrics const & fm = theFontMetrics(font);
684 int const size = int(0.75 * fm.maxAscent());
685 int const y = yo_ - size;
686 int const max_row_width = width_ - size - Inset::TEXT_TO_INSET_OFFSET;
687 int x = is_rtl ? nestMargin() + changebarMargin()
688 : max_row_width - text_metrics_.rightMargin(pm_);
690 // If needed, move the box a bit to avoid overlapping with text.
691 int const rem = max_row_width - row_.width();
693 x += is_rtl ? rem : - rem;
695 if (endlabel == END_LABEL_BOX)
696 pi_.pain.rectangle(x, y, size, size, Color_eolmarker);
698 pi_.pain.fillRectangle(x, y, size, size, Color_eolmarker);
702 case END_LABEL_STATIC: {
703 FontInfo const font = labelFont();
704 FontMetrics const & fm = theFontMetrics(font);
705 docstring const & str = par_.layout().endlabelstring();
706 double const x = is_rtl ? x_ - fm.width(str) : x_;
707 pi_.pain.text(int(x), yo_, str, font);
711 case END_LABEL_NO_LABEL:
712 if (lyxrc.paragraph_markers && size_type(pit_ + 1) < pars_.size()) {
713 docstring const s = docstring(1, char_type(0x00B6));
714 FontInfo f = FontInfo();
715 FontMetrics const & fm = theFontMetrics(f);
716 f.setColor(Color_paragraphmarker);
717 pi_.pain.text(int(x_), yo_, s, f);
725 void RowPainter::paintOnlyInsets()
727 CoordCache const & cache = pi_.base.bv->coordCache();
728 pos_type const end = row_.endpos();
729 for (pos_type pos = row_.pos(); pos != end; ++pos) {
730 // If outer row has changed, nested insets are repaint completely.
731 Inset const * inset = par_.getInset(pos);
734 if (x_ > pi_.base.bv->workWidth()
735 || !cache.getInsets().has(inset))
737 x_ = cache.getInsets().x(inset);
739 bool const pi_selected = pi_.selected;
740 Cursor const & cur = pi_.base.bv->cursor();
741 if (cur.selection() && cur.text() == &text_
742 && cur.normalAnchor().text() == &text_)
743 pi_.selected = row_.sel_beg <= pos && row_.sel_end > pos;
744 paintInset(inset, pos);
745 pi_.selected = pi_selected;
750 void RowPainter::paintText()
752 pos_type const end = row_.endpos();
753 // Spaces at logical line breaks in bidi text must be skipped during
754 // painting. However, they may appear visually in the middle
755 // of a row; they must be skipped, wherever they are...
756 // * logically "abc_[HEBREW_\nHEBREW]"
757 // * visually "abc_[_WERBEH\nWERBEH]"
758 pos_type skipped_sep_vpos = -1;
759 pos_type body_pos = par_.beginOfBody();
761 (body_pos > end || !par_.isLineSeparator(body_pos - 1))) {
765 Layout const & layout = par_.layout();
767 Change change_running;
768 int change_last_x = 0;
770 // check for possible inline completion
771 DocIterator const & inlineCompletionPos = pi_.base.bv->inlineCompletionPos();
772 pos_type inlineCompletionVPos = -1;
773 if (inlineCompletionPos.inTexted()
774 && inlineCompletionPos.text() == &text_
775 && inlineCompletionPos.pit() == pit_
776 && inlineCompletionPos.pos() - 1 >= row_.pos()
777 && inlineCompletionPos.pos() - 1 < row_.endpos()) {
778 // draw logically behind the previous character
779 inlineCompletionVPos = bidi_.log2vis(inlineCompletionPos.pos() - 1);
782 // Use font span to speed things up, see below
786 // If the last logical character is a separator, don't paint it, unless
787 // it's in the last row of a paragraph; see skipped_sep_vpos declaration
788 if (end > 0 && end < par_.size() && par_.isSeparator(end - 1))
789 skipped_sep_vpos = bidi_.log2vis(end - 1);
791 for (pos_type vpos = row_.pos(); vpos < end; ) {
792 if (x_ > pi_.base.bv->workWidth())
795 // Skip the separator at the logical end of the row
796 if (vpos == skipped_sep_vpos) {
801 pos_type const pos = bidi_.vis2log(vpos);
803 if (pos >= par_.size()) {
808 // Use font span to speed things up, see above
809 if (vpos < font_span.first || vpos > font_span.last) {
810 font_span = par_.fontSpan(vpos);
811 font = text_metrics_.displayFont(pit_, vpos);
813 // split font span if inline completion is inside
814 if (font_span.first <= inlineCompletionVPos
815 && font_span.last > inlineCompletionVPos)
816 font_span.last = inlineCompletionVPos;
819 const int width_pos = pm_.singleWidth(pos, font);
821 if (x_ + width_pos < 0) {
826 Change const & change = par_.lookupChange(pos);
827 if (change.changed() && !change_running.changed()) {
828 change_running = change;
829 change_last_x = int(x_);
832 Inset const * inset = par_.getInset(pos);
833 bool const highly_editable_inset = inset
834 && inset->editable();
836 // If we reach the end of a change or if the author changes, paint it.
837 // We also don't paint across things like tables
838 if (change_running.changed() && (highly_editable_inset
839 || !change.changed() || !change_running.isSimilarTo(change))) {
840 // Calculate 1/3 height of the buffer's default font
841 FontMetrics const & fm
842 = theFontMetrics(pi_.base.bv->buffer().params().getFont());
843 int const y_bar = change_running.deleted() ?
844 yo_ - fm.maxAscent() / 3 : yo_ + fm.maxAscent() / 6;
845 pi_.pain.line(change_last_x, y_bar, int(x_), y_bar,
846 change_running.color(), Painter::line_solid, 0.5);
848 // Change might continue with a different author or type
849 if (change.changed() && !highly_editable_inset) {
850 change_running = change;
851 change_last_x = int(x_);
853 change_running.setUnchanged();
856 if (body_pos > 0 && pos == body_pos - 1) {
857 int const lwidth = theFontMetrics(labelFont())
858 .width(layout.labelsep);
860 x_ += row_.label_hfill + lwidth - width_pos;
863 // Is the inline completion in front of character?
864 if (font.isRightToLeft() && vpos == inlineCompletionVPos)
865 paintInlineCompletion(font);
867 if (par_.isSeparator(pos)) {
868 Font const orig_font = text_metrics_.displayFont(pit_, pos);
869 double const orig_x = x_;
872 x_ += row_.separator;
873 paintForeignMark(orig_x, orig_font.language());
877 // If outer row has changed, nested insets are repaint completely.
878 pi_.base.bv->coordCache().insets().add(inset, int(x_), yo_);
880 bool const pi_selected = pi_.selected;
881 Cursor const & cur = pi_.base.bv->cursor();
882 if (cur.selection() && cur.text() == &text_
883 && cur.normalAnchor().text() == &text_)
884 pi_.selected = row_.sel_beg <= pos && row_.sel_end > pos;
885 paintInset(inset, pos);
886 pi_.selected = pi_selected;
890 // paint as many characters as possible.
891 paintFromPos(vpos, change_running.changed());
894 // Is the inline completion after character?
895 if (!font.isRightToLeft() && vpos - 1 == inlineCompletionVPos)
896 paintInlineCompletion(font);
899 // if we reach the end of a struck out range, paint it
900 if (change_running.changed()) {
901 FontMetrics const & fm
902 = theFontMetrics(pi_.base.bv->buffer().params().getFont());
903 int const y_bar = change_running.deleted() ?
904 yo_ - fm.maxAscent() / 3 : yo_ + fm.maxAscent() / 6;
905 pi_.pain.line(change_last_x, y_bar, int(x_), y_bar,
906 change_running.color(), Painter::line_solid, 0.5);
907 change_running.setUnchanged();
912 void RowPainter::paintInlineCompletion(Font const & font)
914 docstring completion = pi_.base.bv->inlineCompletion();
915 FontInfo f = font.fontInfo();
916 bool rtl = font.isRightToLeft();
918 // draw the unique and the non-unique completion part
919 // Note: this is not time-critical as it is
920 // only done once per screen.
921 size_t uniqueTo = pi_.base.bv->inlineCompletionUniqueChars();
922 docstring s1 = completion.substr(0, uniqueTo);
923 docstring s2 = completion.substr(uniqueTo);
924 ColorCode c1 = Color_inlinecompletion;
925 ColorCode c2 = Color_nonunique_inlinecompletion;
935 pi_.pain.text(int(x_), yo_, s1, f);
936 x_ += theFontMetrics(font).width(s1);
941 pi_.pain.text(int(x_), yo_, s2, f);
942 x_ += theFontMetrics(font).width(s2);