]> git.lyx.org Git - lyx.git/blob - src/rowpainter.C
badb0ff2790a6c196c5bce2faf157dc0c332709a
[lyx.git] / src / rowpainter.C
1 /**
2  * \file rowpainter.C
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 "cursor.h"
18 #include "debug.h"
19 #include "bufferparams.h"
20 #include "BufferView.h"
21 #include "encoding.h"
22 #include "gettext.h"
23 #include "language.h"
24 #include "LColor.h"
25 #include "lyxrc.h"
26 #include "lyxrow.h"
27 #include "lyxrow_funcs.h"
28 #include "metricsinfo.h"
29 #include "paragraph.h"
30 #include "paragraph_funcs.h"
31 #include "ParagraphParameters.h"
32 #include "vspace.h"
33
34 #include "frontends/font_metrics.h"
35 #include "frontends/Painter.h"
36
37 #include "insets/insettext.h"
38
39 #include "support/textutils.h"
40
41 using lyx::pos_type;
42
43 using std::endl;
44 using std::max;
45 using std::string;
46
47 extern int NEST_MARGIN;
48 extern int CHANGEBAR_MARGIN;
49
50
51 namespace {
52
53 /**
54  * A class used for painting an individual row of text.
55  */
56 class RowPainter {
57 public:
58         /// initialise and run painter
59         RowPainter(BufferView const & bv, LyXText const & text,
60                 ParagraphList::iterator pit, RowList::iterator rit, int xo, int yo);
61 private:
62         // paint various parts
63         void paintBackground();
64         void paintSelection();
65         void paintAppendix();
66         void paintDepthBar();
67         void paintChangeBar();
68         void paintFirst();
69         void paintLast();
70         void paintForeignMark(double orig_x, LyXFont const & orig_font);
71         void paintHebrewComposeChar(lyx::pos_type & vpos);
72         void paintArabicComposeChar(lyx::pos_type & vpos);
73         void paintChars(lyx::pos_type & vpos, bool hebrew, bool arabic);
74         int paintAppendixStart(int y);
75         void paintText();
76         void paintFromPos(lyx::pos_type & vpos);
77         void paintInset(lyx::pos_type const pos);
78
79         /// return left margin
80         int leftMargin() const;
81
82         /// return the font at the given pos
83         LyXFont const getFont(lyx::pos_type pos) const;
84
85         /// return the label font for this row
86         LyXFont const getLabelFont() const;
87
88         /// return pixel width for the given pos
89         int singleWidth(lyx::pos_type pos) const;
90         int singleWidth(lyx::pos_type pos, char c) const;
91
92         /// bufferview to paint on
93         BufferView const & bv_;
94
95         /// Painter to use
96         Painter & pain_;
97
98         /// LyXText for the row
99         LyXText const & text_;
100
101         /// The row to paint
102         RowList::iterator const rit_;
103         Row & row_;
104
105         /// Row's paragraph
106         mutable ParagraphList::iterator  pit_;
107
108         // Looks ugly - is
109         double xo_;
110         int yo_;
111         double x_;
112         int width_;
113         double separator_;
114         double hfill_;
115         double label_hfill_;
116 };
117
118
119 RowPainter::RowPainter(BufferView const & bv, LyXText const & text,
120      ParagraphList::iterator pit, RowList::iterator rit,
121      int xo, int yo)
122         : bv_(bv), pain_(bv_.painter()), text_(text), rit_(rit), row_(*rit),
123           pit_(pit), xo_(xo), yo_(yo), x_(row_.x()),
124                 width_(text_.textWidth()),
125                 separator_(row_.fill_separator()),
126                 hfill_(row_.fill_hfill()),
127                 label_hfill_(row_.fill_label_hfill())
128 {
129         //lyxerr << "RowPainter: x: " << x_ << " xo: " << xo << " yo: " << yo
130         //      << " pit->y: " << pit_->y
131         //      << " row: " << (pit_->size() ? pit_->getChar(row_.pos()) : 'X') << endl;
132         x_ += xo_;
133
134         // background has already been cleared.
135         if (&text_ == bv_.text())
136                 paintBackground();
137
138         // paint the selection background
139         if (bv_.cursor().selection() && &text_ == bv_.cursor().text())
140                 paintSelection();
141
142         // vertical lines for appendix
143         paintAppendix();
144
145         // environment depth brackets
146         paintDepthBar();
147
148         // changebar
149         paintChangeBar();
150
151         if (row_.pos() == 0)
152                 paintFirst();
153
154         if (row_.endpos() >= pit_->size())
155                 paintLast();
156
157         // paint text
158         paintText();
159 }
160
161
162 /// "temporary"
163 LyXFont const RowPainter::getFont(pos_type pos) const
164 {
165         return text_.getFont(pit_, pos);
166 }
167
168
169 int RowPainter::singleWidth(lyx::pos_type pos) const
170 {
171         return text_.singleWidth(pit_, pos);
172 }
173
174
175 int RowPainter::singleWidth(lyx::pos_type pos, char c) const
176 {
177         LyXFont const & font = text_.getFont(pit_, pos);
178         return text_.singleWidth(pit_, pos, c, font);
179 }
180
181
182 LyXFont const RowPainter::getLabelFont() const
183 {
184         return text_.getLabelFont(pit_);
185 }
186
187
188 int RowPainter::leftMargin() const
189 {
190         return text_.leftMargin(pit_, row_.pos());
191 }
192
193
194 void RowPainter::paintInset(pos_type const pos)
195 {
196         InsetBase const * inset = pit_->getInset(pos);
197         BOOST_ASSERT(inset);
198         PainterInfo pi(const_cast<BufferView *>(&bv_));
199         pi.base.font = getFont(pos);
200         inset->drawSelection(pi, int(x_), yo_ + row_.baseline());
201         inset->draw(pi, int(x_), yo_ + row_.baseline());
202         x_ += inset->width();
203 }
204
205
206 void RowPainter::paintHebrewComposeChar(pos_type & vpos)
207 {
208         pos_type pos = text_.bidi.vis2log(vpos);
209
210         string str;
211
212         // first char
213         char c = pit_->getChar(pos);
214         str += c;
215         ++vpos;
216
217         LyXFont const & font = getFont(pos);
218         int const width = font_metrics::width(c, font);
219         int dx = 0;
220
221         for (pos_type i = pos - 1; i >= 0; --i) {
222                 c = pit_->getChar(i);
223                 if (!Encodings::IsComposeChar_hebrew(c)) {
224                         if (IsPrintableNonspace(c)) {
225                                 int const width2 = singleWidth(i, c);
226                                 // dalet / resh
227                                 dx = (c == 'ø' || c == 'ã')
228                                         ? width2 - width
229                                         : (width2 - width) / 2;
230                         }
231                         break;
232                 }
233         }
234
235         // Draw nikud
236         pain_.text(int(x_) + dx, yo_ + row_.baseline(), str, font);
237 }
238
239
240 void RowPainter::paintArabicComposeChar(pos_type & vpos)
241 {
242         pos_type pos = text_.bidi.vis2log(vpos);
243         string str;
244
245         // first char
246         char c = pit_->getChar(pos);
247         c = pit_->transformChar(c, pos);
248         str += c;
249         ++vpos;
250
251         LyXFont const & font = getFont(pos);
252         int const width = font_metrics::width(c, font);
253         int dx = 0;
254
255         for (pos_type i = pos - 1; i >= 0; --i) {
256                 c = pit_->getChar(i);
257                 if (!Encodings::IsComposeChar_arabic(c)) {
258                         if (IsPrintableNonspace(c)) {
259                                 int const width2 = singleWidth(i, c);
260                                 dx = (width2 - width) / 2;
261                         }
262                         break;
263                 }
264         }
265         // Draw nikud
266         pain_.text(int(x_) + dx, yo_ + row_.baseline(), str, font);
267 }
268
269
270 void RowPainter::paintChars(pos_type & vpos, bool hebrew, bool arabic)
271 {
272         pos_type pos = text_.bidi.vis2log(vpos);
273         pos_type const end = row_.endpos();
274         LyXFont orig_font = getFont(pos);
275
276         // first character
277         string str;
278         str += pit_->getChar(pos);
279         if (arabic) {
280                 unsigned char c = str[0];
281                 str[0] = pit_->transformChar(c, pos);
282         }
283
284         bool prev_struckout = isDeletedText(*pit_, pos);
285         bool prev_newtext = isInsertedText(*pit_, pos);
286
287         // collect as much similar chars as we can
288         for (++vpos; vpos < end && (pos = text_.bidi.vis2log(vpos)) >= 0; ++vpos) {
289                 char c = pit_->getChar(pos);
290
291                 if (!IsPrintableNonspace(c))
292                         break;
293
294                 if (prev_struckout != isDeletedText(*pit_, pos))
295                         break;
296
297                 if (prev_newtext != isInsertedText(*pit_, pos))
298                         break;
299
300                 if (arabic && Encodings::IsComposeChar_arabic(c))
301                         break;
302
303                 if (hebrew && Encodings::IsComposeChar_hebrew(c))
304                         break;
305
306                 if (orig_font != getFont(pos))
307                         break;
308
309                 if (arabic)
310                         c = pit_->transformChar(c, pos);
311
312                 str += c;
313         }
314
315         if (prev_struckout)
316                 orig_font.setColor(LColor::strikeout);
317         else if (prev_newtext)
318                 orig_font.setColor(LColor::newtext);
319
320         // Draw text and set the new x position
321         //lyxerr << "paint row: yo_ " << yo_ << " baseline: " << row_.baseline()
322         //      << "\n";
323         pain_.text(int(x_), yo_ + row_.baseline(), str, orig_font);
324         x_ += font_metrics::width(str, orig_font);
325 }
326
327
328 void RowPainter::paintForeignMark(double orig_x, LyXFont const & orig_font)
329 {
330         if (!lyxrc.mark_foreign_language)
331                 return;
332         if (orig_font.language() == latex_language)
333                 return;
334         if (orig_font.language() == bv_.buffer()->params().language)
335                 return;
336
337         int const y = yo_ + row_.baseline() + 1;
338         pain_.line(int(orig_x), y, int(x_), y, LColor::language);
339 }
340
341
342 void RowPainter::paintFromPos(pos_type & vpos)
343 {
344         pos_type const pos = text_.bidi.vis2log(vpos);
345
346         LyXFont const & orig_font = getFont(pos);
347
348         double const orig_x = x_;
349
350         char const c = pit_->getChar(pos);
351
352         if (c == Paragraph::META_INSET) {
353                 paintInset(pos);
354                 ++vpos;
355                 paintForeignMark(orig_x, orig_font);
356                 return;
357         }
358
359         // usual characters, no insets
360
361         // special case languages
362         bool const hebrew = (orig_font.language()->lang() == "hebrew");
363         bool const arabic =
364                 orig_font.language()->lang() == "arabic" &&
365                 (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
366                 lyxrc.font_norm_type == LyXRC::ISO_10646_1);
367
368         // draw as many chars as we can
369         if ((!hebrew && !arabic)
370                 || (hebrew && !Encodings::IsComposeChar_hebrew(c))
371                 || (arabic && !Encodings::IsComposeChar_arabic(c))) {
372                 paintChars(vpos, hebrew, arabic);
373         } else if (hebrew) {
374                 paintHebrewComposeChar(vpos);
375         } else if (arabic) {
376                 paintArabicComposeChar(vpos);
377         }
378
379         paintForeignMark(orig_x, orig_font);
380 }
381
382
383 void RowPainter::paintBackground()
384 {
385         int const x = int(xo_);
386         int const y = yo_ < 0 ? 0 : yo_;
387         int const h = yo_ < 0 ? row_.height() + yo_ : row_.height();
388         pain_.fillRectangle(x, y, width_, h, text_.backgroundColor());
389 }
390
391
392 void RowPainter::paintSelection()
393 {
394         bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params());
395
396         // the current selection
397         LCursor const & cur = bv_.cursor();
398         int const startx = text_.cursorX(cur.selBegin());
399         int const endx = text_.cursorX(cur.selEnd());
400         int const starty = text_.cursorY(cur.selBegin());
401         int const endy = text_.cursorY(cur.selEnd());
402         ParagraphList::iterator startpit = text_.getPar(cur.selBegin());
403         ParagraphList::iterator endpit = text_.getPar(cur.selEnd());
404         RowList::iterator startrow = startpit->getRow(cur.selBegin().pos());
405         RowList::iterator endrow = endpit->getRow(cur.selEnd().pos());
406         int const h = row_.height();
407
408         int const row_y = pit_->y + row_.y_offset();
409
410         bool const sel_starts_here = startpit == pit_ && startrow == rit_;
411         bool const sel_ends_here   = endpit == pit_ && endrow == rit_;
412         bool const sel_on_one_row  = sel_starts_here && sel_ends_here;
413
414         if (text_.bidi.same_direction()) {
415                 int x;
416                 int w;
417                 if (sel_on_one_row) {
418                         if (startx < endx) {
419                                 x = startx;
420                                 w = endx - startx;
421                         } else {
422                                 x = endx;
423                                 w = startx - endx;
424                         }
425                         pain_.fillRectangle(x, yo_, w, h, LColor::selection);
426                 } else if (sel_starts_here) {
427                         int const x = is_rtl ? 0 : startx;
428                         int const w = is_rtl ? startx : (width_ - startx);
429                         pain_.fillRectangle(x, yo_, w, h, LColor::selection);
430                 } else if (sel_ends_here) {
431                         int const x = is_rtl ? endx : 0;
432                         int const w = is_rtl ? (width_ - endx) : endx;
433                         pain_.fillRectangle(x, yo_, w, h, LColor::selection);
434                 } else if (row_y > starty && row_y < endy) {
435                         pain_.fillRectangle(int(xo_), yo_, width_, h, LColor::selection);
436                 }
437                 return;
438         }
439
440         if ((startpit != pit_ && startrow != rit_ && !is_rtl)
441                 || (endpit != pit_ && endrow != rit_ && is_rtl))
442                 pain_.fillRectangle(int(xo_), yo_,
443                         int(x_), h, LColor::selection);
444
445         pos_type const body_pos = pit_->beginOfBody();
446         pos_type const end = row_.endpos();
447         double tmpx = x_;
448
449         for (pos_type vpos = row_.pos(); vpos < end; ++vpos)  {
450                 pos_type pos = text_.bidi.vis2log(vpos);
451                 double const old_tmpx = tmpx;
452                 if (body_pos > 0 && pos == body_pos - 1) {
453                         LyXLayout_ptr const & layout = pit_->layout();
454                         LyXFont const lfont = getLabelFont();
455
456                         tmpx += label_hfill_ + font_metrics::width(layout->labelsep, lfont);
457
458                         if (pit_->isLineSeparator(body_pos - 1))
459                                 tmpx -= singleWidth(body_pos - 1);
460                 }
461
462                 tmpx += singleWidth(pos);
463
464                 if (hfillExpansion(*pit_, row_, pos)) {
465                         if (pos >= body_pos)
466                                 tmpx += hfill_;
467                         else
468                                 tmpx += label_hfill_;
469                 } else {
470                         if (pit_->isSeparator(pos) && pos >= body_pos)
471                                 tmpx += separator_;
472                 }
473
474                 if (((startpit != pit_ && startrow != rit_)
475                                 || cur.selBegin().pos() <= pos) &&
476                         ((endpit != pit_ && endrow != rit_)
477                                 || pos < cur.selEnd().pos())) {
478                         // Here we do not use x_ as xo_ was added to x_.
479                         pain_.fillRectangle(int(old_tmpx), yo_,
480                                 int(tmpx - old_tmpx + 1), h, LColor::selection);
481                 }
482         }
483
484         if ((startpit != pit_ && startrow != rit_ && is_rtl) ||
485             (endpit != pit_ && endrow != rit_ && !is_rtl)) {
486                 pain_.fillRectangle(int(xo_ + tmpx),
487                         yo_, int(width_ - tmpx), h, LColor::selection);
488         }
489 }
490
491
492 void RowPainter::paintChangeBar()
493 {
494         pos_type const start = row_.pos();
495         pos_type const end = row_.endpos();
496
497         if (start == end || !pit_->isChanged(start, end - 1))
498                 return;
499
500         int const height = text_.isLastRow(pit_, row_)
501                 ? row_.baseline()
502                 : row_.height() + boost::next(rit_)->top_of_text();
503
504         pain_.fillRectangle(4, yo_, 5, height, LColor::changebar);
505 }
506
507
508 void RowPainter::paintAppendix()
509 {
510         if (!pit_->params().appendix())
511                 return;
512
513         // FIXME: can be just width_ ?
514         int const ww = width_;
515
516         int y = yo_;
517
518         if (pit_->params().startOfAppendix())
519                 y += 2 * defaultRowHeight();
520
521         pain_.line(1, y, 1, yo_ + row_.height(), LColor::appendix);
522         pain_.line(ww - 2, y, ww - 2, yo_ + row_.height(), LColor::appendix);
523 }
524
525
526 void RowPainter::paintDepthBar()
527 {
528         Paragraph::depth_type const depth = pit_->getDepth();
529
530         if (depth <= 0)
531                 return;
532
533         Paragraph::depth_type prev_depth = 0;
534         if (!text_.isFirstRow(pit_, row_)) {
535                 ParagraphList::iterator pit2 = pit_;
536                 if (row_.pos() == 0)
537                         --pit2;
538                 prev_depth = pit2->getDepth();
539         }
540
541         Paragraph::depth_type next_depth = 0;
542         if (!text_.isLastRow(pit_, row_)) {
543                 ParagraphList::iterator pit2 = pit_;
544                 if (row_.endpos() >= pit2->size())
545                         ++pit2;
546                 next_depth = pit2->getDepth();
547         }
548
549         for (Paragraph::depth_type i = 1; i <= depth; ++i) {
550                 int const w = NEST_MARGIN / 5;
551                 int x = int(w * i + xo_);
552                 // only consider the changebar space if we're drawing outer left
553                 if (xo_ == 0)
554                         x += CHANGEBAR_MARGIN;
555                 int const h = yo_ + row_.height() - 1 - (i - next_depth - 1) * 3;
556
557                 pain_.line(x, yo_, x, h, LColor::depthbar);
558
559                 if (i > prev_depth)
560                         pain_.fillRectangle(x, yo_, w, 2, LColor::depthbar);
561                 if (i > next_depth)
562                         pain_.fillRectangle(x, h, w, 2, LColor::depthbar);
563         }
564 }
565
566
567 int RowPainter::paintAppendixStart(int y)
568 {
569         LyXFont pb_font;
570         pb_font.setColor(LColor::appendix);
571         pb_font.decSize();
572
573         string const label = _("Appendix");
574         int w = 0;
575         int a = 0;
576         int d = 0;
577         font_metrics::rectText(label, pb_font, w, a, d);
578
579         int const text_start = int(xo_ + (width_ - w) / 2);
580         int const text_end = text_start + w;
581
582         pain_.rectText(text_start, y + d, label, pb_font, LColor::none, LColor::none);
583
584         pain_.line(int(xo_ + 1), y, text_start, y, LColor::appendix);
585         pain_.line(text_end, y, int(xo_ + width_ - 2), y, LColor::appendix);
586
587         return 3 * defaultRowHeight();
588 }
589
590
591 void RowPainter::paintFirst()
592 {
593         ParagraphParameters const & parparams = pit_->params();
594
595         int y_top = 0;
596
597         // start of appendix?
598         if (parparams.startOfAppendix())
599                 y_top += paintAppendixStart(yo_ + y_top + 2 * defaultRowHeight());
600
601         Buffer const & buffer = *bv_.buffer();
602
603         LyXLayout_ptr const & layout = pit_->layout();
604
605         if (buffer.params().paragraph_separation == BufferParams::PARSEP_SKIP) {
606                 if (pit_ != text_.paragraphs().begin()) {
607                         if (layout->latextype == LATEX_PARAGRAPH
608                                 && !pit_->getDepth()) {
609                                 y_top += buffer.params().getDefSkip().inPixels(bv_);
610                         } else {
611                                 LyXLayout_ptr const & playout =
612                                         boost::prior(pit_)->layout();
613                                 if (playout->latextype == LATEX_PARAGRAPH
614                                         && !boost::prior(pit_)->getDepth()) {
615                                         // is it right to use defskip here, too? (AS)
616                                         y_top += buffer.params().getDefSkip().inPixels(bv_);
617                                 }
618                         }
619                 }
620         }
621
622         int const ww = bv_.workWidth();
623
624         bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params());
625         bool const is_seq = isFirstInSequence(pit_, text_.paragraphs());
626         //lyxerr << "paintFirst: " << pit_->id() << " is_seq: " << is_seq << std::endl;
627
628         // should we print a label?
629         if (layout->labeltype >= LABEL_STATIC
630             && (layout->labeltype != LABEL_STATIC
631                       || layout->latextype != LATEX_ENVIRONMENT
632                       || is_seq)) {
633
634                 LyXFont font = getLabelFont();
635                 if (!pit_->getLabelstring().empty()) {
636                         double x = x_;
637                         string const str = pit_->getLabelstring();
638
639                         // this is special code for the chapter layout. This is
640                         // printed in an extra row and has a pagebreak at
641                         // the top.
642                         if (layout->counter == "chapter") {
643                                 if (buffer.params().secnumdepth >= 0) {
644                                         float spacing_val = 1.0;
645                                         if (!parparams.spacing().isDefault()) {
646                                                 spacing_val = parparams.spacing().getValue();
647                                         } else {
648                                                 spacing_val = buffer.params().spacing().getValue();
649                                         }
650
651                                         int const maxdesc =
652                                                 int(font_metrics::maxDescent(font) * layout->spacing.getValue() * spacing_val)
653                                                 + int(layout->parsep) * defaultRowHeight();
654
655                                         if (is_rtl) {
656                                                 x = ww - leftMargin() -
657                                                         font_metrics::width(str, font);
658                                         }
659
660                                         pain_.text(int(x),
661                                                 yo_ + row_.baseline() -
662                                                 row_.ascent_of_text() - maxdesc,
663                                                 str, font);
664                                 }
665                         } else {
666                                 if (is_rtl) {
667                                         x = ww - leftMargin()
668                                                 + font_metrics::width(layout->labelsep, font);
669                                 } else {
670                                         x = x_ - font_metrics::width(layout->labelsep, font)
671                                                 - font_metrics::width(str, font);
672                                 }
673
674                                 pain_.text(int(x), yo_ + row_.baseline(), str, font);
675                         }
676                 }
677
678         // the labels at the top of an environment.
679         // More or less for bibliography
680         } else if (is_seq &&
681                 (layout->labeltype == LABEL_TOP_ENVIRONMENT ||
682                 layout->labeltype == LABEL_BIBLIO ||
683                 layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)) {
684                 LyXFont font = getLabelFont();
685                 if (!pit_->getLabelstring().empty()) {
686                         string const str = pit_->getLabelstring();
687                         float spacing_val = 1.0;
688                         if (!parparams.spacing().isDefault()) {
689                                 spacing_val = parparams.spacing().getValue();
690                         } else {
691                                 spacing_val = buffer.params().spacing().getValue();
692                         }
693
694                         int maxdesc =
695                                 int(font_metrics::maxDescent(font) * layout->spacing.getValue() * spacing_val
696                                 + (layout->labelbottomsep * defaultRowHeight()));
697
698                         double x = x_;
699                         if (layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
700                                 x = ((is_rtl ? leftMargin() : x_)
701                                          + ww - text_.rightMargin(*pit_)) / 2;
702                                 x -= font_metrics::width(str, font) / 2;
703                         } else if (is_rtl) {
704                                 x = ww - leftMargin() -
705                                         font_metrics::width(str, font);
706                         }
707                         pain_.text(int(x),
708                             yo_ + row_.baseline() - row_.ascent_of_text() - maxdesc,
709                                   str, font);
710                 }
711         }
712 }
713
714
715 void RowPainter::paintLast()
716 {
717         int const ww = bv_.workWidth();
718         bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params());
719         int const endlabel = getEndLabel(pit_, text_.paragraphs());
720
721         // draw an endlabel
722         switch (endlabel) {
723         case END_LABEL_BOX:
724         case END_LABEL_FILLED_BOX: {
725                 LyXFont const font = getLabelFont();
726                 int const size = int(0.75 * font_metrics::maxAscent(font));
727                 int const y = yo_ + row_.baseline() - size;
728                 int x = is_rtl ? NEST_MARGIN + CHANGEBAR_MARGIN: ww - size;
729
730                 if (row_.fill() <= size)
731                         x += (size - row_.fill() + 1) * (is_rtl ? -1 : 1);
732
733                 if (endlabel == END_LABEL_BOX)
734                         pain_.rectangle(x, y, size, size, LColor::eolmarker);
735                 else
736                         pain_.fillRectangle(x, y, size, size, LColor::eolmarker);
737                 break;
738         }
739
740         case END_LABEL_STATIC: {
741                 LyXFont font = getLabelFont();
742                 string const & str = pit_->layout()->endlabelstring();
743                 double const x = is_rtl ?
744                         x_ - font_metrics::width(str, font)
745                         : ww - text_.rightMargin(*pit_) - row_.fill();
746                 pain_.text(int(x), yo_ + row_.baseline(), str, font);
747                 break;
748         }
749
750         case END_LABEL_NO_LABEL:
751                 break;
752         }
753 }
754
755
756 void RowPainter::paintText()
757 {
758         pos_type const end = row_.endpos();
759         pos_type body_pos = pit_->beginOfBody();
760         if (body_pos > 0 &&
761                 (body_pos > end || !pit_->isLineSeparator(body_pos - 1))) {
762                 body_pos = 0;
763         }
764
765         LyXLayout_ptr const & layout = pit_->layout();
766
767         bool running_strikeout = false;
768         bool is_struckout = false;
769         int last_strikeout_x = 0;
770
771         for (pos_type vpos = row_.pos(); vpos < end; ) {
772                 if (x_ > bv_.workWidth())
773                         break;
774
775                 pos_type pos = text_.bidi.vis2log(vpos);
776
777                 if (pos >= pit_->size()) {
778                         ++vpos;
779                         continue;
780                 }
781
782                 if (x_ + singleWidth(pos) < 0) {
783                         x_ += singleWidth(pos);
784                         ++vpos;
785                         continue;
786                 }
787
788                 is_struckout = isDeletedText(*pit_, pos);
789
790                 if (is_struckout && !running_strikeout) {
791                         running_strikeout = true;
792                         last_strikeout_x = int(x_);
793                 }
794
795                 bool const highly_editable_inset = pit_->isInset(pos)
796                         && isHighlyEditableInset(pit_->getInset(pos));
797
798                 // if we reach the end of a struck out range, paint it
799                 // we also don't paint across things like tables
800                 if (running_strikeout && (highly_editable_inset || !is_struckout)) {
801                         int const middle = yo_ + (row_.baseline() + row_.top_of_text()) / 2;
802                         pain_.line(last_strikeout_x, middle, int(x_), middle,
803                                 LColor::strikeout, Painter::line_solid, Painter::line_thin);
804                         running_strikeout = false;
805                 }
806
807                 if (body_pos > 0 && pos == body_pos - 1) {
808                         int const lwidth = font_metrics::width(layout->labelsep,
809                                 getLabelFont());
810
811                         x_ += label_hfill_ + lwidth - singleWidth(body_pos - 1);
812                 }
813
814                 if (pit_->isHfill(pos)) {
815                         x_ += 1;
816
817                         int const y0 = yo_ + row_.baseline();
818                         int const y1 = y0 - defaultRowHeight() / 2;
819
820                         pain_.line(int(x_), y1, int(x_), y0, LColor::added_space);
821
822                         if (hfillExpansion(*pit_, row_, pos)) {
823                                 int const y2 = (y0 + y1) / 2;
824
825                                 if (pos >= body_pos) {
826                                         pain_.line(int(x_), y2, int(x_ + hfill_), y2,
827                                                   LColor::added_space,
828                                                   Painter::line_onoffdash);
829                                         x_ += hfill_;
830                                 } else {
831                                         pain_.line(int(x_), y2, int(x_ + label_hfill_), y2,
832                                                   LColor::added_space,
833                                                   Painter::line_onoffdash);
834                                         x_ += label_hfill_;
835                                 }
836                                 pain_.line(int(x_), y1, int(x_), y0, LColor::added_space);
837                         }
838                         x_ += 2;
839                         ++vpos;
840                 } else if (pit_->isSeparator(pos)) {
841                         x_ += singleWidth(pos);
842                         if (pos >= body_pos)
843                                 x_ += separator_;
844                         ++vpos;
845                 } else {
846                         paintFromPos(vpos);
847                 }
848         }
849
850         // if we reach the end of a struck out range, paint it
851         if (running_strikeout) {
852                 int const middle = yo_ + (row_.baseline() + row_.top_of_text()) / 2;
853                 pain_.line(last_strikeout_x, middle, int(x_), middle,
854                         LColor::strikeout, Painter::line_solid, Painter::line_thin);
855                 running_strikeout = false;
856         }
857 }
858
859
860 int paintPars(BufferView const & bv, LyXText const & text,
861         ParagraphList::iterator pit, int xo, int yo, int y)
862 {
863         //lyxerr << "  paintRows: pit: " << &*pit << endl;
864         int const y2 = bv.painter().paperHeight();
865         y -= bv.top_y();
866
867         ParagraphList::iterator end = text.paragraphs().end();
868
869         for ( ; pit != end; ++pit) {
870                 RowList::iterator row = pit->rows.begin();
871                 RowList::iterator rend = pit->rows.end();
872
873                 for ( ; row != rend; ++row) {
874                         RowPainter(bv, text, pit, row, xo, y + yo);
875                         y += row->height();
876                 }
877                 if (yo + y >= y2)
878                         break;
879         }
880
881         return y;
882 }
883
884 } // namespace anon
885
886
887 int paintText(BufferView const & bv)
888 {
889         ParagraphList::iterator pit;
890         bv.text()->updateParPositions();
891         bv.text()->getRowNearY(bv.top_y(), pit);
892         //lyxerr << "top_y: " << bv.top_y() << " y: " << pit->y << endl;
893         return paintPars(bv, *bv.text(), pit, 0, 0, pit->y);
894 }
895
896
897 void paintTextInset(LyXText const & text, PainterInfo & pi, int xo, int yo)
898 {
899         paintPars(*pi.base.bv, text, text.paragraphs().begin(), xo, yo, 0);
900 }