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 "mathed/InsetMath.h"
43 #include "support/debug.h"
44 #include "support/gettext.h"
45 #include "support/textutils.h"
47 #include "support/lassert.h"
48 #include <boost/crc.hpp>
54 using frontend::Painter;
55 using frontend::FontMetrics;
57 RowPainter::RowPainter(PainterInfo & pi,
58 Text const & text, pit_type pit, Row const & row, Bidi & bidi, int x, int y)
59 : pi_(pi), text_(text),
60 text_metrics_(pi_.base.bv->textMetrics(&text)),
61 pars_(text.paragraphs()),
62 row_(row), pit_(pit), par_(text.paragraphs()[pit]),
63 pm_(text_metrics_.parMetrics(pit)),
64 bidi_(bidi), change_(pi_.change_),
65 xo_(x), yo_(y), width_(text_metrics_.width()),
66 line_thickness_(1.0), line_offset_(2)
68 bidi_.computeTables(par_, pi_.base.bv->buffer(), row_);
70 if (lyxrc.zoom >= 100) {
71 // derive the line thickness from zoom factor
72 // the zoom is given in percent
73 // (increase thickness at 150%, 250% etc.)
74 line_thickness_ = (float)(int((lyxrc.zoom + 50) / 100.0));
75 // adjust line_offset_ too
76 line_offset_ = int(2 * line_thickness_) + 1;
81 //lyxerr << "RowPainter: x: " << x_ << " xo: " << xo_ << " yo: " << yo_ << endl;
84 LASSERT(pit >= 0, /**/);
85 LASSERT(pit < int(text.paragraphs().size()), /**/);
89 FontInfo RowPainter::labelFont() const
91 FontInfo f = text_.labelFont(par_);
93 if (row_.begin_margin_sel || pi_.selected)
94 f.setPaintColor(Color_selectiontext);
99 int RowPainter::leftMargin() const
101 return text_metrics_.leftMargin(text_metrics_.width(), pit_,
105 // If you want to debug inset metrics uncomment the following line:
106 //#define DEBUG_METRICS
107 // This draws green lines around each inset.
110 void RowPainter::paintInset(Inset const * inset, pos_type const pos)
112 Font const font = text_metrics_.displayFont(pit_, pos);
114 LASSERT(inset, return);
115 // Backup full_repaint status because some insets (InsetTabular)
116 // requires a full repaint
117 bool pi_full_repaint = pi_.full_repaint;
119 // FIXME: We should always use font, see documentation of
120 // noFontChange() in Inset.h.
121 pi_.base.font = inset->noFontChange() ?
122 pi_.base.bv->buffer().params().getFont().fontInfo() :
124 pi_.ltr_pos = (bidi_.level(pos) % 2 == 0);
125 pi_.change_ = change_.changed() ? change_ : par_.lookupChange(pos);
127 int const x1 = int(x_);
128 pi_.base.bv->coordCache().insets().add(inset, x1, yo_);
129 // insets are painted completely. Recursive
130 // FIXME: it is wrong to completely paint the background
131 // if we want to do single row painting.
132 inset->drawBackground(pi_, x1, yo_);
133 inset->drawSelection(pi_, x1, yo_);
134 inset->draw(pi_, x1, yo_);
136 Dimension const & dim = pm_.insetDimension(inset);
138 paintForeignMark(x_, font.language(), dim.descent());
142 // Restore full_repaint status.
143 pi_.full_repaint = pi_full_repaint;
146 int const x2 = x1 + dim.wid;
147 int const y1 = yo_ + dim.des;
148 int const y2 = yo_ - dim.asc;
149 pi_.pain.line(x1, y1, x1, y2, Color_green);
150 pi_.pain.line(x1, y1, x2, y1, Color_green);
151 pi_.pain.line(x2, y1, x2, y2, Color_green);
152 pi_.pain.line(x1, y2, x2, y2, Color_green);
157 void RowPainter::paintHebrewComposeChar(pos_type & vpos, FontInfo const & font)
159 pos_type pos = bidi_.vis2log(vpos);
164 char_type c = par_.getChar(pos);
168 int const width = theFontMetrics(font).width(c);
171 for (pos_type i = pos - 1; i >= 0; --i) {
173 if (!Encodings::isHebrewComposeChar(c)) {
174 if (isPrintableNonspace(c)) {
175 int const width2 = pm_.singleWidth(i,
176 text_metrics_.displayFont(pit_, i));
177 dx = (c == 0x05e8 || // resh
178 c == 0x05d3) // dalet
180 : (width2 - width) / 2;
187 pi_.pain.text(int(x_) + dx, yo_, str, font);
191 void RowPainter::paintArabicComposeChar(pos_type & vpos, FontInfo const & font)
193 pos_type pos = bidi_.vis2log(vpos);
197 char_type c = par_.getChar(pos);
198 c = par_.transformChar(c, pos);
202 int const width = theFontMetrics(font).width(c);
205 for (pos_type i = pos - 1; i >= 0; --i) {
207 if (!Encodings::isArabicComposeChar(c)) {
208 if (isPrintableNonspace(c)) {
209 int const width2 = pm_.singleWidth(i,
210 text_metrics_.displayFont(pit_, i));
211 dx = (width2 - width) / 2;
217 pi_.pain.text(int(x_) + dx, yo_, str, font);
221 void RowPainter::paintChars(pos_type & vpos, FontInfo const & font,
222 bool hebrew, bool arabic)
224 // This method takes up 70% of time when typing
225 pos_type pos = bidi_.vis2log(vpos);
227 char_type prev_char = par_.getChar(pos);
228 vector<char_type> str;
230 str.push_back(prev_char);
233 char_type c = str[0];
238 str[0] = par_.transformChar(c, pos);
241 pos_type const end = row_.endpos();
242 FontSpan const font_span = par_.fontSpan(pos);
243 // Track-change status.
244 Change const & change_running = par_.lookupChange(pos);
247 bool const selection = (pos >= row_.sel_beg && pos < row_.sel_end)
251 bool const spell_state =
252 lyxrc.spellcheck_continuously && par_.isMisspelled(pos);
254 // collect as much similar chars as we can
255 for (++vpos ; vpos < end ; ++vpos) {
256 // Work-around bug #6920
257 // The bug can be reproduced with DejaVu font under Linux.
258 // The issue is that we compute the metrics character by character
259 // in ParagraphMetrics::singleWidth(); but we paint word by word
260 // for performance reason.
261 // Maybe a more general fix would be draw character by character
262 // for some predefined fonts on some platform. In arabic and
263 // Hebrew we already do paint this way.
264 if (prev_char == 'f')
267 pos = bidi_.vis2log(vpos);
268 if (pos < font_span.first || pos > font_span.last)
271 bool const new_selection = pos >= row_.sel_beg && pos < row_.sel_end;
272 if (new_selection != selection)
273 // Selection ends or starts here.
276 bool const new_spell_state =
277 lyxrc.spellcheck_continuously && par_.isMisspelled(pos);
278 if (new_spell_state != spell_state)
279 // Spell checker state changed here.
282 Change const & change = par_.lookupChange(pos);
283 if (!change_running.isSimilarTo(change))
284 // Track change type or author has changed.
287 char_type c = par_.getChar(pos);
292 if (!isPrintableNonspace(c))
295 /* Because we do our own bidi, at this point the strings are
296 * already in visual order. However, Qt also applies its own
297 * bidi algorithm to strings that it paints to the screen.
298 * Therefore, if we were to paint Hebrew/Arabic words as a
299 * single string, the letters in the words would get reversed
300 * again. In order to avoid that, we don't collect Hebrew/
301 * Arabic characters, but rather paint them one at a time.
302 * See also http://thread.gmane.org/gmane.editors.lyx.devel/79740
307 /* FIXME: these checks are irrelevant, since 'arabic' and
308 * 'hebrew' alone are already going to trigger a break.
309 * However, this should not be removed completely, because
310 * if an alternative solution is found which allows grouping
311 * of arabic and hebrew characters, then these breaks may have
314 if (arabic && Encodings::isArabicComposeChar(c))
317 if (hebrew && Encodings::isHebrewComposeChar(c))
326 c = par_.transformChar(c, pos);
327 /* see comment in hebrew, explaining why we break */
335 docstring s(&str[0], str.size());
338 s.replace(0,1,from_ascii(" "));
340 if (!selection && !change_running.changed()) {
341 x_ += pi_.pain.text(int(x_), yo_, s, font);
345 FontInfo copy = font;
346 if (change_running.changed())
347 copy.setPaintColor(change_running.color());
349 copy.setPaintColor(Color_selectiontext);
351 x_ += pi_.pain.text(int(x_), yo_, s, copy);
355 void RowPainter::paintForeignMark(double orig_x, Language const * lang,
358 if (!lyxrc.mark_foreign_language)
360 if (lang == latex_language)
362 if (lang == pi_.base.bv->buffer().params().language)
365 int const y = yo_ + 1 + desc + int(line_thickness_/2);
366 pi_.pain.line(int(orig_x), y, int(x_), y, Color_language,
367 Painter::line_solid, line_thickness_);
371 void RowPainter::paintMisspelledMark(double orig_x, bool changed)
373 // if changed the misspelled marker gets placed slightly lower than normal
374 // to avoid drawing at the same vertical offset
375 int const y = yo_ + (changed ? int(line_thickness_ + 1.0) : 0) + line_offset_;
376 pi_.pain.line(int(orig_x), y, int(x_), y, Color_error,
377 Painter::line_onoffdash, line_thickness_);
381 void RowPainter::paintFromPos(pos_type & vpos, bool changed)
383 pos_type const pos = bidi_.vis2log(vpos);
384 Font const orig_font = text_metrics_.displayFont(pit_, pos);
385 double const orig_x = x_;
387 // usual characters, no insets
388 char_type const c = par_.getChar(pos);
390 // special case languages
391 string const & lang = orig_font.language()->lang();
392 bool const hebrew = lang == "hebrew";
393 bool const arabic = lang == "arabic_arabtex" || lang == "arabic_arabi" ||
397 bool const misspelled_ =
398 lyxrc.spellcheck_continuously && par_.isMisspelled(pos);
400 // draw as many chars as we can
401 if ((!hebrew && !arabic)
402 || (hebrew && !Encodings::isHebrewComposeChar(c))
403 || (arabic && !Encodings::isArabicComposeChar(c))) {
404 paintChars(vpos, orig_font.fontInfo(), hebrew, arabic);
406 paintHebrewComposeChar(vpos, orig_font.fontInfo());
408 paintArabicComposeChar(vpos, orig_font.fontInfo());
411 paintForeignMark(orig_x, orig_font.language());
413 if (lyxrc.spellcheck_continuously && misspelled_) {
414 paintMisspelledMark(orig_x, changed);
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_metrics_.isLastRow(pit_, row_)
437 pi_.pain.fillRectangle(5, yo_ - row_.ascent(), 3, height, Color_changebar);
441 void RowPainter::paintAppendix()
443 // only draw the appendix frame once (for the main text)
444 if (!par_.params().appendix() || !text_.isMainText())
447 int y = yo_ - row_.ascent();
449 if (par_.params().startOfAppendix())
450 y += 2 * defaultRowHeight();
452 pi_.pain.line(1, y, 1, yo_ + row_.height(), Color_appendix);
453 pi_.pain.line(width_ - 2, y, width_ - 2, yo_ + row_.height(), Color_appendix);
457 void RowPainter::paintDepthBar()
459 depth_type const depth = par_.getDepth();
464 depth_type prev_depth = 0;
465 if (!text_metrics_.isFirstRow(pit_, row_)) {
466 pit_type pit2 = pit_;
469 prev_depth = pars_[pit2].getDepth();
472 depth_type next_depth = 0;
473 if (!text_metrics_.isLastRow(pit_, row_)) {
474 pit_type pit2 = pit_;
475 if (row_.endpos() >= pars_[pit2].size())
477 next_depth = pars_[pit2].getDepth();
480 for (depth_type i = 1; i <= depth; ++i) {
481 int const w = nestMargin() / 5;
482 int x = int(xo_) + w * i;
483 // only consider the changebar space if we're drawing outermost text
484 if (text_.isMainText())
485 x += changebarMargin();
487 int const starty = yo_ - row_.ascent();
488 int const h = row_.height() - 1 - (i - next_depth - 1) * 3;
490 pi_.pain.line(x, starty, x, starty + h, Color_depthbar);
493 pi_.pain.fillRectangle(x, starty, w, 2, Color_depthbar);
495 pi_.pain.fillRectangle(x, starty + h, w, 2, Color_depthbar);
500 int RowPainter::paintAppendixStart(int y)
502 FontInfo pb_font = sane_font;
503 pb_font.setColor(Color_appendix);
510 docstring const label = _("Appendix");
511 theFontMetrics(pb_font).rectText(label, w, a, d);
513 int const text_start = int(xo_ + (width_ - w) / 2);
514 int const text_end = text_start + w;
516 pi_.pain.rectText(text_start, y + d, label, pb_font, Color_none, Color_none);
518 pi_.pain.line(int(xo_ + 1), y, text_start, y, Color_appendix);
519 pi_.pain.line(text_end, y, int(xo_ + width_ - 2), y, Color_appendix);
521 return 3 * defaultRowHeight();
525 void RowPainter::paintFirst()
527 ParagraphParameters const & pparams = par_.params();
528 Buffer const & buffer = pi_.base.bv->buffer();
529 BufferParams const & bparams = buffer.params();
530 Layout const & layout = par_.layout();
534 // start of appendix?
535 if (pparams.startOfAppendix())
536 y_top += paintAppendixStart(yo_ - row_.ascent() + 2 * defaultRowHeight());
538 if (bparams.paragraph_separation == BufferParams::ParagraphSkipSeparation
540 if (layout.latextype == LATEX_PARAGRAPH
541 && !par_.getDepth()) {
542 y_top += bparams.getDefSkip().inPixels(*pi_.base.bv);
544 Layout 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 += bparams.getDefSkip().inPixels(*pi_.base.bv);
553 bool const is_rtl = text_.isRTL(par_);
554 bool const is_seq = text_.isFirstInSequence(pit_);
555 //lyxerr << "paintFirst: " << par_.id() << " is_seq: " << is_seq << endl;
557 // should we print a label?
558 if (layout.labeltype >= LABEL_STATIC
559 && (layout.labeltype != LABEL_STATIC
560 || layout.latextype != LATEX_ENVIRONMENT
563 FontInfo const font = labelFont();
564 FontMetrics const & fm = theFontMetrics(font);
566 docstring const str = par_.labelString();
570 // this is special code for the chapter layout. This is
571 // printed in an extra row and has a pagebreak at
573 if (layout.counter == "chapter") {
574 double spacing_val = 1.0;
575 if (!pparams.spacing().isDefault()) {
576 spacing_val = pparams.spacing().getValue();
578 spacing_val = bparams.spacing().getValue();
581 int const labeladdon = int(fm.maxHeight() * layout.spacing.getValue() * spacing_val);
583 int const maxdesc = int(fm.maxDescent() * layout.spacing.getValue() * spacing_val)
584 + int(layout.parsep) * defaultRowHeight();
587 x = width_ - leftMargin() -
591 pi_.pain.text(int(x), yo_ - maxdesc - labeladdon, str, font);
594 x = width_ - leftMargin()
595 + fm.width(layout.labelsep);
597 x = x_ - fm.width(layout.labelsep)
601 pi_.pain.text(int(x), yo_, str, font);
605 // the labels at the top of an environment.
606 // More or less for bibliography
608 (layout.labeltype == LABEL_TOP_ENVIRONMENT ||
609 layout.labeltype == LABEL_BIBLIO ||
610 layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)) {
611 FontInfo const font = labelFont();
612 docstring const str = par_.labelString();
614 double spacing_val = 1.0;
615 if (!pparams.spacing().isDefault())
616 spacing_val = pparams.spacing().getValue();
618 spacing_val = bparams.spacing().getValue();
620 FontMetrics const & fm = theFontMetrics(font);
622 int const labeladdon = int(fm.maxHeight()
623 * layout.spacing.getValue() * spacing_val);
626 int(fm.maxDescent() * layout.spacing.getValue() * spacing_val
627 + (layout.labelbottomsep * defaultRowHeight()));
630 if (layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
633 x += (width_ - text_metrics_.rightMargin(pm_) - leftMargin()) / 2;
634 x -= fm.width(str) / 2;
636 x = width_ - leftMargin() - fm.width(str);
638 pi_.pain.text(int(x), yo_ - maxdesc - labeladdon, str, font);
644 /** Check if the current paragraph is the last paragraph in a
646 static int getEndLabel(pit_type p, Text const & text)
648 ParagraphList const & pars = text.paragraphs();
650 depth_type par_depth = pars[p].getDepth();
651 while (pit != pit_type(pars.size())) {
652 Layout const & layout = pars[pit].layout();
653 int const endlabeltype = layout.endlabeltype;
655 if (endlabeltype != END_LABEL_NO_LABEL) {
656 if (p + 1 == pit_type(pars.size()))
659 depth_type const next_depth =
660 pars[p + 1].getDepth();
661 if (par_depth > next_depth ||
662 (par_depth == next_depth && layout != pars[p + 1].layout()))
668 pit = text.outerHook(pit);
669 if (pit != pit_type(pars.size()))
670 par_depth = pars[pit].getDepth();
672 return END_LABEL_NO_LABEL;
676 void RowPainter::paintLast()
678 bool const is_rtl = text_.isRTL(par_);
679 int const endlabel = getEndLabel(pit_, text_);
681 // paint imaginary end-of-paragraph character
683 Change const & change = par_.lookupChange(par_.size());
684 if (change.changed()) {
685 FontMetrics const & fm =
686 theFontMetrics(pi_.base.bv->buffer().params().getFont());
687 int const length = fm.maxAscent() / 2;
688 Color col = change.color();
690 pi_.pain.line(int(x_) + 1, yo_ + 2, int(x_) + 1, yo_ + 2 - length, col,
691 Painter::line_solid, 3);
693 if (change.deleted()) {
694 pi_.pain.line(int(x_) + 1 - length, yo_ + 2, int(x_) + 1 + length,
695 yo_ + 2, col, Painter::line_solid, 3);
697 pi_.pain.line(int(x_) + 1 - length, yo_ + 2, int(x_) + 1,
698 yo_ + 2, col, Painter::line_solid, 3);
706 case END_LABEL_FILLED_BOX: {
707 FontInfo const font = labelFont();
708 FontMetrics const & fm = theFontMetrics(font);
709 int const size = int(0.75 * fm.maxAscent());
710 int const y = yo_ - size;
711 int const max_row_width = width_ - size - Inset::TEXT_TO_INSET_OFFSET;
712 int x = is_rtl ? nestMargin() + changebarMargin()
713 : max_row_width - text_metrics_.rightMargin(pm_);
715 // If needed, move the box a bit to avoid overlapping with text.
716 int const rem = max_row_width - row_.width();
718 x += is_rtl ? rem : - rem;
720 if (endlabel == END_LABEL_BOX)
721 pi_.pain.rectangle(x, y, size, size, Color_eolmarker);
723 pi_.pain.fillRectangle(x, y, size, size, Color_eolmarker);
727 case END_LABEL_STATIC: {
728 FontInfo const font = labelFont();
729 FontMetrics const & fm = theFontMetrics(font);
730 docstring const & str = par_.layout().endlabelstring();
731 double const x = is_rtl ? x_ - fm.width(str) : x_;
732 pi_.pain.text(int(x), yo_, str, font);
736 case END_LABEL_NO_LABEL:
737 if (lyxrc.paragraph_markers && size_type(pit_ + 1) < pars_.size()) {
738 docstring const s = docstring(1, char_type(0x00B6));
739 FontInfo f = FontInfo();
740 FontMetrics const & fm = theFontMetrics(f);
741 f.setColor(Color_paragraphmarker);
742 pi_.pain.text(int(x_), yo_, s, f);
750 void RowPainter::paintOnlyInsets()
752 CoordCache const & cache = pi_.base.bv->coordCache();
753 pos_type const end = row_.endpos();
754 for (pos_type pos = row_.pos(); pos != end; ++pos) {
755 // If outer row has changed, nested insets are repaint completely.
756 Inset const * inset = par_.getInset(pos);
757 bool const nested_inset = inset &&
758 ((inset->asInsetMath() &&
759 !inset->asInsetMath()->asMacroTemplate())
760 || inset->asInsetText()
761 || inset->asInsetTabular());
764 if (x_ > pi_.base.bv->workWidth()
765 || !cache.getInsets().has(inset))
767 x_ = cache.getInsets().x(inset);
769 bool const pi_selected = pi_.selected;
770 Cursor const & cur = pi_.base.bv->cursor();
771 if (cur.selection() && cur.text() == &text_
772 && cur.normalAnchor().text() == &text_)
773 pi_.selected = row_.sel_beg <= pos && row_.sel_end > pos;
774 paintInset(inset, pos);
775 pi_.selected = pi_selected;
780 void RowPainter::paintText()
782 pos_type const end = row_.endpos();
783 // Spaces at logical line breaks in bidi text must be skipped during
784 // painting. However, they may appear visually in the middle
785 // of a row; they must be skipped, wherever they are...
786 // * logically "abc_[HEBREW_\nHEBREW]"
787 // * visually "abc_[_WERBEH\nWERBEH]"
788 pos_type skipped_sep_vpos = -1;
789 pos_type body_pos = par_.beginOfBody();
791 (body_pos > end || !par_.isLineSeparator(body_pos - 1))) {
795 Layout const & layout = par_.layout();
797 Change change_running;
798 int change_last_x = 0;
800 // check for possible inline completion
801 DocIterator const & inlineCompletionPos = pi_.base.bv->inlineCompletionPos();
802 pos_type inlineCompletionVPos = -1;
803 if (inlineCompletionPos.inTexted()
804 && inlineCompletionPos.text() == &text_
805 && inlineCompletionPos.pit() == pit_
806 && inlineCompletionPos.pos() - 1 >= row_.pos()
807 && inlineCompletionPos.pos() - 1 < row_.endpos()) {
808 // draw logically behind the previous character
809 inlineCompletionVPos = bidi_.log2vis(inlineCompletionPos.pos() - 1);
812 // Use font span to speed things up, see below
816 // If the last logical character is a separator, don't paint it, unless
817 // it's in the last row of a paragraph; see skipped_sep_vpos declaration
818 if (end > 0 && end < par_.size() && par_.isSeparator(end - 1))
819 skipped_sep_vpos = bidi_.log2vis(end - 1);
821 for (pos_type vpos = row_.pos(); vpos < end; ) {
822 if (x_ > pi_.base.bv->workWidth())
825 // Skip the separator at the logical end of the row
826 if (vpos == skipped_sep_vpos) {
831 pos_type const pos = bidi_.vis2log(vpos);
833 if (pos >= par_.size()) {
838 // Use font span to speed things up, see above
839 if (vpos < font_span.first || vpos > font_span.last) {
840 font_span = par_.fontSpan(vpos);
841 font = text_metrics_.displayFont(pit_, vpos);
843 // split font span if inline completion is inside
844 if (font_span.first <= inlineCompletionVPos
845 && font_span.last > inlineCompletionVPos)
846 font_span.last = inlineCompletionVPos;
849 const int width_pos = pm_.singleWidth(pos, font);
851 if (x_ + width_pos < 0) {
856 Change const & change = par_.lookupChange(pos);
857 if (change.changed() && !change_running.changed()) {
858 change_running = change;
859 change_last_x = int(x_);
862 Inset const * inset = par_.getInset(pos);
863 bool const highly_editable_inset = inset
864 && inset->editable();
866 // If we reach the end of a change or if the author changes, paint it.
867 // We also don't paint across things like tables
868 if (change_running.changed() && (highly_editable_inset
869 || !change.changed() || !change_running.isSimilarTo(change))) {
870 // Calculate 1/3 height of the buffer's default font
871 FontMetrics const & fm
872 = theFontMetrics(pi_.base.bv->buffer().params().getFont());
873 int const y_bar = change_running.deleted() ?
874 yo_ - fm.maxAscent() / 3 : yo_ + line_offset_;
875 pi_.pain.line(change_last_x, y_bar, int(x_), y_bar,
876 change_running.color(), Painter::line_solid, line_thickness_);
878 // Change might continue with a different author or type
879 if (change.changed() && !highly_editable_inset) {
880 change_running = change;
881 change_last_x = int(x_);
883 change_running.setUnchanged();
886 if (body_pos > 0 && pos == body_pos - 1) {
887 int const lwidth = theFontMetrics(labelFont())
888 .width(layout.labelsep);
890 x_ += row_.label_hfill + lwidth - width_pos;
893 // Is the inline completion in front of character?
894 if (font.isRightToLeft() && vpos == inlineCompletionVPos)
895 paintInlineCompletion(font);
897 if (par_.isSeparator(pos)) {
898 Font const orig_font = text_metrics_.displayFont(pit_, pos);
899 double const orig_x = x_;
902 x_ += row_.separator;
903 paintForeignMark(orig_x, orig_font.language());
907 // If outer row has changed, nested insets are repaint completely.
908 pi_.base.bv->coordCache().insets().add(inset, int(x_), yo_);
910 bool const pi_selected = pi_.selected;
911 Cursor const & cur = pi_.base.bv->cursor();
912 if (cur.selection() && cur.text() == &text_
913 && cur.normalAnchor().text() == &text_)
914 pi_.selected = row_.sel_beg <= pos && row_.sel_end > pos;
915 paintInset(inset, pos);
916 pi_.selected = pi_selected;
920 // paint as many characters as possible.
921 paintFromPos(vpos, change_running.changed());
924 // Is the inline completion after character?
925 if (!font.isRightToLeft() && vpos - 1 == inlineCompletionVPos)
926 paintInlineCompletion(font);
929 // if we reach the end of a struck out range, paint it
930 if (change_running.changed()) {
931 FontMetrics const & fm
932 = theFontMetrics(pi_.base.bv->buffer().params().getFont());
933 int const y_bar = change_running.deleted() ?
934 yo_ - fm.maxAscent() / 3 : yo_ + line_offset_;
935 pi_.pain.line(change_last_x, y_bar, int(x_), y_bar,
936 change_running.color(), Painter::line_solid, line_thickness_);
937 change_running.setUnchanged();
942 void RowPainter::paintSelection()
944 if (!row_.selection())
946 Cursor const & curs = pi_.base.bv->cursor();
947 DocIterator beg = curs.selectionBegin();
949 beg.pos() = row_.sel_beg;
951 DocIterator end = curs.selectionEnd();
953 end.pos() = row_.sel_end;
955 bool const begin_boundary = beg.pos() >= row_.endpos();
956 bool const end_boundary = row_.sel_end == row_.endpos();
958 DocIterator cur = beg;
959 cur.boundary(begin_boundary);
960 int x1 = text_metrics_.cursorX(beg.top(), begin_boundary);
961 int x2 = text_metrics_.cursorX(end.top(), end_boundary);
962 int const y1 = yo_ - row_.ascent();
963 int const y2 = y1 + row_.height();
965 int const rm = text_.isMainText() ? pi_.base.bv->rightMargin() : 0;
966 int const lm = text_.isMainText() ? pi_.base.bv->leftMargin() : 0;
969 if (row_.begin_margin_sel) {
970 if (text_.isRTL(beg.paragraph())) {
971 pi_.pain.fillRectangle(int(xo_ + x1), y1,
972 text_metrics_.width() - rm - x1, y2 - y1, Color_selection);
974 pi_.pain.fillRectangle(int(xo_ + lm), y1, x1 - lm, y2 - y1,
979 if (row_.end_margin_sel) {
980 if (text_.isRTL(beg.paragraph())) {
981 pi_.pain.fillRectangle(int(xo_ + lm), y1, x2 - lm, y2 - y1,
984 pi_.pain.fillRectangle(int(xo_ + x2), y1, text_metrics_.width() - rm - x2,
985 y2 - y1, Color_selection);
989 // if we are on a boundary from the beginning, it's probably
990 // a RTL boundary and we jump to the other side directly as this
991 // segement is 0-size and confuses the logic below
995 // go through row and draw from RTL boundary to RTL boundary
997 bool draw_now = false;
999 // simplified cursorForward code below which does not
1000 // descend into insets and which does not go into the
1001 // next line. Compare the logic with the original cursorForward
1003 // if left of boundary -> just jump to right side, but
1004 // for RTL boundaries don't, because: abc|DDEEFFghi -> abcDDEEF|Fghi
1005 if (cur.boundary()) {
1006 cur.boundary(false);
1007 } else if (text_metrics_.isRTLBoundary(cur.pit(), cur.pos() + 1)) {
1008 // in front of RTL boundary -> Stay on this side of the boundary
1009 // because: ab|cDDEEFFghi -> abc|DDEEFFghi
1018 if (cur.pos() == row_.endpos())
1023 // the previous segment was just drawn, now the next starts
1024 x1 = text_metrics_.cursorX(cur.top(), cur.boundary());
1027 if (!(cur < end) || draw_now) {
1028 x2 = text_metrics_.cursorX(cur.top(), cur.boundary());
1029 pi_.pain.fillRectangle(int(xo_ + min(x1, x2)), y1, abs(x2 - x1),
1030 y2 - y1, Color_selection);
1032 // reset x1, so it is set again next round (which will be on the
1033 // right side of a boundary or at the selection end)
1040 void RowPainter::paintInlineCompletion(Font const & font)
1042 docstring completion = pi_.base.bv->inlineCompletion();
1043 FontInfo f = font.fontInfo();
1044 bool rtl = font.isRightToLeft();
1046 // draw the unique and the non-unique completion part
1047 // Note: this is not time-critical as it is
1048 // only done once per screen.
1049 size_t uniqueTo = pi_.base.bv->inlineCompletionUniqueChars();
1050 docstring s1 = completion.substr(0, uniqueTo);
1051 docstring s2 = completion.substr(uniqueTo);
1052 ColorCode c1 = Color_inlinecompletion;
1053 ColorCode c2 = Color_nonunique_inlinecompletion;
1061 if (s1.size() > 0) {
1063 pi_.pain.text(int(x_), yo_, s1, f);
1064 x_ += theFontMetrics(font).width(s1);
1067 if (s2.size() > 0) {
1069 pi_.pain.text(int(x_), yo_, s2, f);
1070 x_ += theFontMetrics(font).width(s2);