]> git.lyx.org Git - lyx.git/blob - src/RowPainter.cpp
* ca/Intro.lyx from Daniel
[lyx.git] / src / RowPainter.cpp
1 /**
2  * \file RowPainter.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author various
7  * \author John Levon
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "RowPainter.h"
15
16 #include "Buffer.h"
17 #include "CoordCache.h"
18 #include "Cursor.h"
19 #include "BufferParams.h"
20 #include "BufferView.h"
21 #include "Bullet.h"
22 #include "Changes.h"
23 #include "Language.h"
24 #include "Layout.h"
25 #include "LyXRC.h"
26 #include "Row.h"
27 #include "MetricsInfo.h"
28 #include "Paragraph.h"
29 #include "ParagraphList.h"
30 #include "ParagraphParameters.h"
31 #include "Text.h"
32 #include "TextMetrics.h"
33
34 #include "frontends/FontMetrics.h"
35 #include "frontends/Painter.h"
36
37 #include "support/debug.h"
38 #include "support/gettext.h"
39 #include "support/lassert.h"
40
41 #include <algorithm>
42
43 using namespace std;
44
45 namespace lyx {
46
47 using frontend::Painter;
48 using frontend::FontMetrics;
49
50
51 RowPainter::RowPainter(PainterInfo & pi,
52         Text const & text, Row const & row, int x, int y)
53         : pi_(pi), text_(text),
54           tm_(pi_.base.bv->textMetrics(&text)),
55           row_(row), par_(text.paragraphs()[row.pit()]),
56           xo_(x), yo_(y)
57 {
58         x_ = row_.left_margin + xo_;
59
60         //lyxerr << "RowPainter: x: " << x_ << " xo: " << xo_ << " yo: " << yo_ << endl;
61         //row_.dump();
62
63         LBUFERR(row.pit() >= 0);
64         LBUFERR(row.pit() < int(text.paragraphs().size()));
65 }
66
67
68 FontInfo RowPainter::labelFont(bool end) const
69 {
70         FontInfo f = tm_.labelDisplayFont(row_.pit()).fontInfo();
71         // selected text?
72         if ((end ? row_.end_margin_sel : row_.begin_margin_sel)
73             || pi_.selected)
74                 f.setPaintColor(Color_selectiontext);
75         return f;
76 }
77
78
79 // If you want to debug inset metrics uncomment the following line:
80 //#define DEBUG_METRICS
81 // This draws green lines around each inset.
82
83
84 void RowPainter::paintInset(Row::Element const & e) const
85 {
86         // Handle selection (first left/right, then middle).
87         pi_.selected_left = pi_.selected
88                             || (row_.isRTL() ? row_.end_margin_sel : row_.begin_margin_sel);
89         pi_.selected_right = pi_.selected
90                              || (row_.isRTL() ? row_.begin_margin_sel : row_.end_margin_sel);
91         bool const pi_selected = pi_.selected;
92         Cursor const & cur = pi_.base.bv->cursor();
93         if (cur.selection() && cur.text() == &text_
94                 && cur.normalAnchor().text() == &text_)
95                 pi_.selected = row_.sel_beg <= e.pos && row_.sel_end > e.pos;
96
97         LASSERT(e.inset, return);
98         // Backup full_repaint status because some insets (InsetTabular)
99         // requires a full repaint
100         bool const pi_full_repaint = pi_.full_repaint;
101         bool const pi_do_spellcheck = pi_.do_spellcheck;
102         Change const pi_change = pi_.change;
103         int const pi_textwidth = pi_.base.textwidth;
104
105         pi_.base.font = e.inset->inheritFont() ? e.font.fontInfo() :
106                 pi_.base.bv->buffer().params().getFont().fontInfo();
107         pi_.ltr_pos = !e.font.isVisibleRightToLeft();
108         pi_.change = pi_.change.changed() ? pi_.change : e.change;
109         pi_.do_spellcheck &= e.inset->allowSpellCheck();
110         pi_.base.textwidth += e.extra;
111
112         int const x1 = int(x_);
113         pi_.base.bv->coordCache().insets().add(e.inset, x1, yo_);
114         // insets are painted completely. Recursive
115         // FIXME: it is wrong to completely paint the background
116         // if we want to do single row painting.
117         e.inset->drawBackground(pi_, x1, yo_);
118         e.inset->drawSelection(pi_, x1, yo_);
119         e.inset->draw(pi_, x1, yo_);
120         paintTextDecoration(e);
121
122         // Restore full_repaint status.
123         pi_.full_repaint = pi_full_repaint;
124         pi_.change = pi_change;
125         pi_.do_spellcheck = pi_do_spellcheck;
126         pi_.selected = pi_selected;
127         pi_.base.textwidth = pi_textwidth;
128
129 #ifdef DEBUG_METRICS
130         Dimension const & dim = pi_.base.bv->coordCache().insets().dim(e.inset);
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);
138 #endif
139 }
140
141
142 void RowPainter::paintLanguageMarkings(Row::Element const & e) const
143 {
144         paintForeignMark(e);
145         paintNoSpellingMark(e);
146 }
147
148
149 void RowPainter::paintForeignMark(Row::Element const & e) const
150 {
151         Language const * lang = e.font.language();
152         if (!lyxrc.mark_foreign_language)
153                 return;
154         if (lang == latex_language)
155                 return;
156         if (lang == pi_.base.bv->buffer().params().language)
157                 return;
158
159         int const desc = e.inset ? e.dim.descent() : 0;
160         int const y = yo_ + min(3 * pi_.base.solidLineOffset() / 2 + desc,
161                                 row_.descent() - 1);
162         pi_.pain.line(int(x_), y, int(x_ + e.full_width() - 1), y, Color_language,
163                       Painter::line_solid, pi_.base.solidLineThickness());
164 }
165
166
167 void RowPainter::paintNoSpellingMark(Row::Element const & e) const
168 {
169         //if (!lyxrc.mark_no_spelling)
170         //      return;
171         if (e.font.language() == latex_language)
172                 return;
173         if (e.font.fontInfo().nospellcheck() != FONT_ON)
174                 return;
175
176         // We at the same voffset than the misspelled mark, since
177         // these two are mutually exclusive
178         int const desc = e.inset ? e.dim.descent() : 0;
179         int y = yo_ + pi_.base.solidLineOffset() + desc
180                 + pi_.base.solidLineThickness()
181                 + (e.change.changed() ? pi_.base.solidLineThickness() + 1 : 0)
182                 + 1;
183         // Make sure that the mark does not go below the row rectangle
184         y = min(y, yo_ + row_.descent() - 1);
185
186         pi_.pain.line(int(x_), y, int(x_ + e.full_width()), y, Color_language,
187                       Painter::line_onoffdash, pi_.base.solidLineThickness());
188 }
189
190
191 void RowPainter::paintMisspelledMark(Row::Element const & e) const
192 {
193         if (e.font.fontInfo().nospellcheck() == FONT_ON)
194                 return;
195         // if changed the misspelled marker gets placed slightly lower than normal
196         // to avoid drawing at the same vertical offset
197         FontMetrics const & fm = theFontMetrics(e.font);
198         int const thickness = max(fm.lineWidth(), 2);
199         int y = yo_ + pi_.base.solidLineOffset() + pi_.base.solidLineThickness()
200                 + (e.change.changed() ? pi_.base.solidLineThickness() + 1 : 0)
201                 + 1 + thickness / 2;
202         // Make sure that the mark does not go below the row rectangle
203         y = min(y, yo_ + row_.descent() - 1);
204
205         //FIXME: this could be computed only once, it is probably not costly.
206         // check for cursor position
207         // don't draw misspelled marker for words at cursor position
208         // we don't want to disturb the process of text editing
209         DocIterator const nw = pi_.base.bv->cursor().newWord();
210         pos_type cpos = -1;
211         if (!nw.empty() && par_.id() == nw.paragraph().id()) {
212                 cpos = nw.pos();
213                 if (cpos > 0 && cpos == par_.size() && !par_.isWordSeparator(cpos-1))
214                         --cpos;
215                 else if (cpos > 0 && par_.isWordSeparator(cpos))
216                         --cpos;
217         }
218
219         pos_type pos = e.pos;
220         while (pos < e.pos + pos_type(e.str.length())) {
221                 if (!par_.isMisspelled(pos)) {
222                         ++pos;
223                         continue;
224                 }
225
226                 FontSpan const & range = par_.getSpellRange(pos);
227
228                 // Skip element which are being edited
229                 if (range.contains(cpos)) {
230                         // the range includes the last element
231                         pos = range.last + 1;
232                         continue;
233                 }
234
235                 int x1 = fm.pos2x(e.str, range.first - e.pos,
236                                   e.isRTL(), e.extra);
237                 int x2 = fm.pos2x(e.str, min(range.last - e.pos + 1,
238                                                                          pos_type(e.str.length())),
239                                                                          e.isRTL(), e.extra);
240                 if (x1 > x2)
241                         swap(x1, x2);
242
243                 pi_.pain.line(int(x_ + x1), y, int(x_ + x2), y,
244                               Color_error,
245                               Painter::line_onoffdash, thickness);
246                 pos = range.last + 1;
247         }
248 }
249
250
251 void RowPainter::paintStringAndSel(Row::Element const & e) const
252 {
253         // at least part of text selected?
254         bool const some_sel = (e.endpos >= row_.sel_beg && e.pos < row_.sel_end)
255                 || pi_.selected;
256         // all the text selected?
257         bool const all_sel = (e.pos >= row_.sel_beg && e.endpos < row_.sel_end)
258                 || pi_.selected;
259
260         if (all_sel || e.change.changed()) {
261                 Font copy = e.font;
262                 Color const col = e.change.changed() ? e.change.color()
263                                                      : Color_selectiontext;
264                 copy.fontInfo().setPaintColor(col);
265                 pi_.pain.text(int(x_), yo_, e.str, copy, e.extra, e.full_width());
266         } else if (!some_sel) {
267                 pi_.pain.text(int(x_), yo_, e.str, e.font, e.extra, e.full_width());
268         } else {
269                 pi_.pain.text(int(x_), yo_, e.str, e.font, Color_selectiontext,
270                               max(row_.sel_beg, e.pos) - e.pos,
271                               min(row_.sel_end, e.endpos) - e.pos,
272                               e.extra, e.full_width());
273         }
274 }
275
276
277 void RowPainter::paintTextDecoration(Row::Element const & e) const
278 {
279         // element selected?
280         bool const sel = (e.pos >= row_.sel_beg && e.endpos <= row_.sel_end)
281                 || pi_.selected;
282         FontInfo copy = e.font.fontInfo();
283         if (sel || e.change.changed()) {
284                 Color const col = e.change.changed() ? e.change.color()
285                                                      : Color_selectiontext;
286                 copy.setPaintColor(col);
287         }
288         pi_.pain.textDecoration(copy, int(x_), yo_, int(e.full_width()));
289 }
290
291
292 void RowPainter::paintChange(Row::Element const & e) const
293 {
294         e.change.paintCue(pi_, x_, yo_, x_ + e.full_width(), e.font.fontInfo());
295 }
296
297
298 void RowPainter::paintChangeBar() const
299 {
300         int const x = pi_.base.bv->leftMargin() - pi_.base.bv->zoomedPixels(7);
301         Dimension const & cdim = row_.contents_dim();
302         pi_.pain.fillRectangle(x, yo_ - cdim.ascent(),
303                                3, cdim.height(), Color_changebar);
304 }
305
306
307 void RowPainter::paintAppendix() const
308 {
309         // only draw the appendix frame once (for the main text)
310         if (!par_.params().appendix() || !text_.isMainText())
311                 return;
312
313         int y = yo_ - row_.ascent();
314
315         if (par_.params().startOfAppendix())
316                 y += 2 * defaultRowHeight();
317
318         pi_.pain.line(1, y, 1, yo_ + row_.height(), Color_appendix);
319         pi_.pain.line(tm_.width() - 2, y, tm_.width() - 2, yo_ + row_.height(), Color_appendix);
320 }
321
322
323 void RowPainter::paintDepthBar() const
324 {
325         depth_type const depth = par_.getDepth();
326         ParagraphList const & pars = text_.paragraphs();
327
328         if (depth <= 0)
329                 return;
330
331         depth_type prev_depth = 0;
332         if (!tm_.isFirstRow(row_)) {
333                 pit_type pit2 = row_.pit();
334                 if (row_.pos() == 0)
335                         --pit2;
336                 prev_depth = pars[pit2].getDepth();
337         }
338
339         depth_type next_depth = 0;
340         if (!tm_.isLastRow(row_)) {
341                 pit_type pit2 = row_.pit();
342                 if (row_.endpos() >= pars[pit2].size())
343                         ++pit2;
344                 next_depth = pars[pit2].getDepth();
345         }
346
347         for (depth_type i = 1; i <= depth; ++i) {
348                 int const w = nestMargin() / 5;
349                 int x = int(xo_) + w * i;
350                 // only consider the changebar space if we're drawing outermost text
351                 if (text_.isMainText())
352                         x += pi_.base.bv->leftMargin() - changebarMargin();
353
354                 int const starty = yo_ - row_.ascent();
355                 int const h =  row_.height() - 1 - (i - next_depth - 1) * 3;
356
357                 pi_.pain.line(x, starty, x, starty + h, Color_depthbar);
358
359                 if (i > prev_depth)
360                         pi_.pain.fillRectangle(x, starty, w, 2, Color_depthbar);
361                 if (i > next_depth)
362                         pi_.pain.fillRectangle(x, starty + h, w, 2, Color_depthbar);
363         }
364 }
365
366
367 void RowPainter::paintAppendixStart(int y) const
368 {
369         FontInfo pb_font = sane_font;
370         pb_font.setColor(Color_appendix);
371         pb_font.decSize();
372
373         int w = 0;
374         int a = 0;
375         int d = 0;
376
377         docstring const label = _("Appendix");
378         theFontMetrics(pb_font).rectText(label, w, a, d);
379
380         int const text_start = int(xo_ + (tm_.width() - w) / 2);
381         int const text_end = text_start + w;
382
383         pi_.pain.rectText(text_start, y + d, label, pb_font, Color_none, Color_none);
384
385         pi_.pain.line(int(xo_ + 1), y, text_start, y, Color_appendix);
386         pi_.pain.line(text_end, y, int(xo_ + tm_.width() - 2), y, Color_appendix);
387 }
388
389
390 void RowPainter::paintTooLargeMarks(bool const left, bool const right) const
391 {
392         int const lwid = pi_.base.dottedLineThickness();
393         Dimension const & cdim = row_.contents_dim();
394         if (left) {
395                 int const x = pi_.base.bv->leftMargin() - lwid;
396                 pi_.pain.line(x, yo_ - cdim.ascent(), x, yo_ + cdim.descent(),
397                               Color_scroll, Painter::line_onoffdash, lwid);
398         }
399         if (right) {
400                 int const x = pi_.base.bv->workWidth() - pi_.base.bv->rightMargin();
401                 pi_.pain.line(x, yo_ - cdim.ascent(), x, yo_ + cdim.descent(),
402                               Color_scroll, Painter::line_onoffdash, lwid);
403         }
404 }
405
406
407 void RowPainter::paintFirst() const
408 {
409         Layout const & layout = par_.layout();
410
411         // start of appendix?
412         if (par_.params().startOfAppendix())
413             paintAppendixStart(yo_ - row_.ascent() + 2 * defaultRowHeight());
414
415         bool const is_first =
416                 text_.isFirstInSequence(row_.pit()) || !layout.isParagraphGroup();
417         //lyxerr << "paintFirst: " << par_.id() << " is_seq: " << is_seq << endl;
418
419         if (layout.labelIsInline()
420             && (layout.labeltype != LABEL_STATIC || is_first))
421                 paintLabel();
422         else if (is_first && layout.labelIsAbove())
423                 paintTopLevelLabel();
424 }
425
426
427 void RowPainter::paintLabel() const
428 {
429         docstring const & str = par_.labelString();
430         if (str.empty())
431                 return;
432
433         // different font for label separation and string
434         Layout const & layout = par_.layout();
435         FontInfo const font = labelFont(false);
436         FontMetrics const & fm = theFontMetrics(font);
437         FontInfo lfont = font;
438
439         // bullet?
440         if (layout.labeltype == LABEL_ITEMIZE && par_.itemdepth < 4) {
441                 // get label font size from document properties
442                 lfont.setSize(pi_.base.bv->buffer().params().user_defined_bullet(par_.itemdepth).getFontSize());
443                 // realize to avoid assertion
444                 lfont.realize(sane_font);
445         }
446
447         FontMetrics const & lfm = theFontMetrics(lfont);
448
449         int const x = row_.isRTL() ? row_.width() + fm.width(layout.labelsep)
450                                    : row_.left_margin - fm.width(layout.labelsep) - lfm.width(str);
451
452         pi_.pain.text(int(xo_) + x, yo_, str, lfont);
453 }
454
455
456 void RowPainter::paintTopLevelLabel() const
457 {
458         BufferParams const & bparams = pi_.base.bv->buffer().params();
459         ParagraphParameters const & pparams = par_.params();
460         Layout const & layout = par_.layout();
461         FontInfo const font = labelFont(false);
462         docstring const str = par_.labelString();
463         if (str.empty())
464                 return;
465
466         double spacing_val = 1.0;
467         if (!pparams.spacing().isDefault())
468                 spacing_val = pparams.spacing().getValue();
469         else
470                 spacing_val = bparams.spacing().getValue();
471
472         FontMetrics const & fm = theFontMetrics(font);
473
474         int const labeladdon = int(fm.maxHeight()
475                 * layout.spacing.getValue() * spacing_val);
476
477         int maxdesc =
478                 int(fm.maxDescent() * layout.spacing.getValue() * spacing_val
479                 + (layout.labelbottomsep * defaultRowHeight()));
480
481         double x = x_;
482         if (layout.labeltype == LABEL_CENTERED) {
483                 // The 'size + 1' is weird, but it makes sure that we get the
484                 // left margin of non-first row.
485                 int leftm = tm_.leftMargin(row_.pit(), par_.size() + 1);
486                 int rightm = tm_.rightMargin(row_.pit());
487                 if (row_.isRTL())
488                         swap(leftm, rightm);
489                 /* Currently, x points at row_.left_margin (which contains the
490                  * indent). First remove that, and then center the title with
491                  * respect to the left and right margins.
492                  */
493                 x += leftm - row_.left_margin + (tm_.width() - leftm -rightm) / 2
494                         - fm.width(str) / 2;
495         } else if (row_.isRTL()) {
496                 x = xo_ + tm_.width() - row_.right_margin - fm.width(str);
497         }
498         pi_.pain.text(int(x), yo_ - maxdesc - labeladdon, str, font);
499 }
500
501
502 void RowPainter::paintLast() const
503 {
504         int const endlabel = text_.getEndLabel(row_.pit());
505         switch (endlabel) {
506         case END_LABEL_BOX:
507         case END_LABEL_FILLED_BOX: {
508                 FontInfo font = labelFont(true);
509                 if (font.realColor() != Color_selectiontext)
510                         font.setPaintColor(Color_eolmarker);
511                 FontMetrics const & fm = theFontMetrics(font);
512                 int const size = int(0.75 * fm.maxAscent());
513                 int const y = yo_ - size;
514
515                 // If needed, move the box a bit to avoid overlapping with text.
516                 int x = 0;
517                 if (row_.isRTL()) {
518                         int const normal_x = nestMargin() + changebarMargin();
519                         x = min(normal_x, row_.left_margin - size - Inset::textOffset(pi_.base.bv));
520                 } else {
521                         int const normal_x = tm_.width() - row_.right_margin
522                                 - size - Inset::textOffset(pi_.base.bv);
523                         x = max(normal_x, row_.width());
524                 }
525
526                 if (endlabel == END_LABEL_BOX)
527                         pi_.pain.rectangle(int(xo_) + x, y, size, size, font.realColor());
528                 else
529                         pi_.pain.fillRectangle(int(xo_) + x, y, size, size, font.realColor());
530                 break;
531         }
532
533         case END_LABEL_STATIC: {
534                 FontInfo const font = labelFont(true);
535                 FontMetrics const & fm = theFontMetrics(font);
536                 docstring const & str = par_.layout().endlabelstring();
537                 double const x = row_.isRTL() ? row_.left_margin - fm.width(str) : row_.width();
538                 pi_.pain.text(xo_ + x, yo_, str, font);
539                 break;
540         }
541
542         case END_LABEL_NO_LABEL:
543                 break;
544         }
545 }
546
547
548 void RowPainter::paintOnlyInsets()
549 {
550         for (Row::Element const & e : row_) {
551                 if (e.type == Row::INSET) {
552                         paintInset(e);
553                         // The markings of foreign languages
554                         // and of text ignored for spellchecking
555                         paintLanguageMarkings(e);
556                         // change tracking (not for insets that handle it themselves)
557                         if (!e.inset->canPaintChange(*pi_.base.bv))
558                                 paintChange(e);
559                 }
560
561                 // extra is the extrawidth band-aid described in redoParagraphs
562                 x_ +=  e.full_width() + ((e.type == Row::INSET) ? e.extra : 0);
563         }
564 }
565
566
567 void RowPainter::paintText()
568 {
569         for (Row::Element const & e : row_) {
570                 switch (e.type) {
571                 case Row::STRING:
572                 case Row::VIRTUAL:
573                         paintStringAndSel(e);
574
575                         // Paint the spelling marks if enabled.
576                         if (lyxrc.spellcheck_continuously && pi_.do_spellcheck && !pi_.pain.isNull())
577                                 paintMisspelledMark(e);
578                         break;
579
580                 case Row::INSET:
581                         paintInset(e);
582                         break;
583
584                 case Row::SPACE:
585                 case Row::MARGINSPACE:
586                         paintTextDecoration(e);
587                 }
588
589                 // The markings of foreign languages
590                 // and of text ignored for spellchecking
591                 paintLanguageMarkings(e);
592
593                 // change tracking (not for insets that handle it themselves)
594                 if (e.type != Row::INSET || ! e.inset->canPaintChange(*pi_.base.bv))
595                         paintChange(e);
596
597                 // extra is the extrawidth band-aid described in redoParagraphs
598                 x_ +=  e.full_width() + ((e.type == Row::INSET) ? e.extra : 0);
599         }
600 }
601
602
603 void RowPainter::paintSelection() const
604 {
605         if (!row_.selection())
606                 return;
607
608         int const y1 = yo_ - row_.contents_dim().asc;
609         int const y2 = yo_ + row_.contents_dim().des;
610
611         // The top selection
612         if (row_.begin_margin_sel)
613                 pi_.pain.fillRectangle(int(xo_), yo_ - row_.ascent(),
614                                        tm_.width(), row_.ascent() - row_.contents_dim().asc,
615                                        Color_selection);
616
617         // The left margin selection
618         if (row_.isRTL() ? row_.end_margin_sel : row_.begin_margin_sel)
619                 pi_.pain.fillRectangle(int(xo_), y1, row_.left_margin, y2 - y1,
620                                        Color_selection);
621
622         // go through row and draw from RTL boundary to RTL boundary
623         double x = xo_ + row_.left_margin;
624         for (auto const & e : row_) {
625                 // These are the same tests as in paintStringAndSel, except
626                 // that all_sel has an additional clause that triggers for end
627                 // of paragraph markers. The clause was not used in
628                 // paintStringAndSel to avoid changing the drawing color.
629                 // at least part of text selected?
630                 bool const some_sel = (e.endpos >= row_.sel_beg && e.pos < row_.sel_end)
631                         || pi_.selected;
632                 // all the text selected?
633                 bool const all_sel = (e.pos >= row_.sel_beg && e.endpos < row_.sel_end)
634                     || (e.isVirtual() && e.pos == row_.endpos() && row_.end_margin_sel)
635                     || pi_.selected;
636
637                 if (all_sel) {
638                         // the 3rd argument is written like that to avoid rounding issues
639                         pi_.pain.fillRectangle(int(x), y1,
640                                                int(x + e.full_width()) - int(x), y2 - y1,
641                                                Color_selection);
642                 } else if (some_sel) {
643                         pos_type const from = min(max(row_.sel_beg, e.pos), e.endpos);
644                         pos_type const to = max(min(row_.sel_end, e.endpos), e.pos);
645                         double x1 = e.pos2x(from);
646                         double x2 = e.pos2x(to);
647                         if (x1 > x2)
648                                 swap(x1, x2);
649                         // the 3rd argument is written like that to avoid rounding issues
650                         pi_.pain.fillRectangle(int(x + x1), y1, int(x2 + x) - int(x1 + x),
651                                                y2 - y1, Color_selection);
652                 }
653                 x += e.full_width();
654         }
655
656         // the right margin selection
657         if (row_.isRTL() ? row_.begin_margin_sel : row_.end_margin_sel)
658                 pi_.pain.fillRectangle(int(x), y1,
659                                        int(xo_ + tm_.width()) - int(x), y2 - y1,
660                                        Color_selection);
661         // The bottom selection
662         if (row_.end_margin_sel)
663                 pi_.pain.fillRectangle(int(xo_), yo_ + row_.contents_dim().des,
664                                        tm_.width(), row_.descent() - row_.contents_dim().des,
665                                        Color_selection);
666 }
667
668
669 void RowPainter::paintBookmark(int num) const
670 {
671         BufferView const * bv = pi_.base.bv;
672         FontInfo fi = bv->buffer().params().getFont().fontInfo();
673         FontMetrics const & fm = theFontMetrics(fi);
674         fi.setColor(Color_bookmark);
675         // ❶ U+2776 DINGBAT NEGATIVE CIRCLED DIGIT ONE
676         char_type const ch = 0x2775 + num;
677         int const x = row_.isRTL()
678                 ? bv->workWidth() - bv->rightMargin() + (bv->defaultMargin() - fm.width(ch)) / 2
679                 : bv->leftMargin() - (bv->defaultMargin() + fm.width(ch)) / 2;
680         pi_.pain.text(x, yo_, ch, fi);
681 }
682
683
684 } // namespace lyx