]> git.lyx.org Git - lyx.git/blob - src/rowpainter.cpp
* lfuns doxification for math macros
[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 "Bidi.h"
17 #include "Buffer.h"
18 #include "CoordCache.h"
19 #include "Cursor.h"
20 #include "support/debug.h"
21 #include "BufferParams.h"
22 #include "BufferView.h"
23 #include "Changes.h"
24 #include "Encoding.h"
25 #include "support/gettext.h"
26 #include "Language.h"
27 #include "Layout.h"
28 #include "LyXRC.h"
29 #include "Row.h"
30 #include "MetricsInfo.h"
31 #include "Paragraph.h"
32 #include "ParagraphMetrics.h"
33 #include "paragraph_funcs.h"
34 #include "ParagraphParameters.h"
35 #include "TextMetrics.h"
36 #include "VSpace.h"
37
38 #include "frontends/FontMetrics.h"
39 #include "frontends/Painter.h"
40
41 #include "insets/InsetText.h"
42
43 #include "support/textutils.h"
44
45 #include <boost/crc.hpp>
46
47 #include <ostream>
48
49 using namespace std;
50
51 namespace lyx {
52
53 using frontend::Painter;
54 using frontend::FontMetrics;
55
56 RowPainter::RowPainter(PainterInfo & pi,
57         Text const & text, pit_type pit, Row const & row, Bidi & bidi, int x, int y)
58         : pi_(pi), text_(text),
59           text_metrics_(pi_.base.bv->textMetrics(&text)),
60           pars_(text.paragraphs()),
61           row_(row), pit_(pit), par_(text.paragraphs()[pit]),
62           pm_(text_metrics_.parMetrics(pit)),
63           bidi_(bidi), erased_(pi_.erased_),
64           xo_(x), yo_(y), width_(text_metrics_.width())
65 {
66         bidi_.computeTables(par_, pi_.base.bv->buffer(), row_);
67         x_ = row_.x + xo_;
68
69         //lyxerr << "RowPainter: x: " << x_ << " xo: " << xo_ << " yo: " << yo_ << endl;
70         //row_.dump();
71
72         BOOST_ASSERT(pit >= 0);
73         BOOST_ASSERT(pit < int(text.paragraphs().size()));
74 }
75
76
77 FontInfo const RowPainter::getLabelFont() const
78 {
79         return text_.getLabelFont(pi_.base.bv->buffer(), par_);
80 }
81
82
83 int RowPainter::leftMargin() const
84 {
85         return text_metrics_.leftMargin(text_metrics_.width(), pit_,
86                 row_.pos());
87 }
88
89 // If you want to debug inset metrics uncomment the following line:
90 //#define DEBUG_METRICS
91 // This draws green lines around each inset.
92
93
94 void RowPainter::paintInset(Inset const * inset, pos_type const pos)
95 {
96         Font const font = text_metrics_.getDisplayFont(pit_, pos);
97
98         BOOST_ASSERT(inset);
99         // FIXME: We should always use font, see documentation of
100         // noFontChange() in Inset.h.
101         pi_.base.font = inset->noFontChange() ?
102                 pi_.base.bv->buffer().params().getFont().fontInfo() :
103                 font.fontInfo();
104         pi_.ltr_pos = (bidi_.level(pos) % 2 == 0);
105         pi_.erased_ = erased_ || par_.isDeleted(pos);
106         pi_.base.bv->coordCache().insets().add(inset, int(x_), yo_);
107         // insets are painted completely. Recursive
108         inset->drawSelection(pi_, int(x_), yo_);
109         inset->draw(pi_, int(x_), yo_);
110
111         Dimension const & dim = pm_.insetDimension(inset);
112
113         paintForeignMark(x_, font.language(), dim.descent());
114
115         x_ += dim.width();
116
117 #ifdef DEBUG_METRICS
118         int const x1 = int(x_ - dim.width());
119         Dimension dim2;
120         BOOST_ASSERT(max_witdh_ > 0);
121         int right_margin = text_metrics_.rightMargin(pm_);
122         int const w = max_witdh_ - leftMargin() - right_margin;
123         MetricsInfo mi(pi_.base.bv, font.fontInfo(), w);
124         inset->metrics(mi, dim2);
125         if (dim.wid != dim2.wid)
126                 lyxerr << "Error: inset " << to_ascii(inset->getInsetName())
127                        << " draw width " << dim.width()
128                        << "> metrics width " << dim2.wid << "." << endl;
129         if (dim->asc != dim2.asc)
130                 lyxerr << "Error: inset " << to_ascii(inset->getInsetName())
131                        << " draw ascent " << dim.ascent()
132                        << "> metrics ascent " << dim2.asc << "." << endl;
133         if (dim2.descent() != dim.des)
134                 lyxerr << "Error: inset " << to_ascii(inset->getInsetName())
135                        << " draw ascent " << dim.descent()
136                        << "> metrics descent " << dim2.des << "." << endl;
137         BOOST_ASSERT(dim2.wid == dim.wid);
138         BOOST_ASSERT(dim2.asc == dim.asc);
139         BOOST_ASSERT(dim2.des == dim.des);
140         int const x2 = x1 + dim.wid;
141         int const y1 = yo_ + dim.des;
142         int const y2 = yo_ - dim.asc;
143         pi_.pain.line(x1, y1, x1, y2, Color_green);
144         pi_.pain.line(x1, y1, x2, y1, Color_green);
145         pi_.pain.line(x2, y1, x2, y2, Color_green);
146         pi_.pain.line(x1, y2, x2, y2, Color_green);
147 #endif
148 }
149
150
151 void RowPainter::paintHebrewComposeChar(pos_type & vpos, FontInfo const & font)
152 {
153         pos_type pos = bidi_.vis2log(vpos);
154
155         docstring str;
156
157         // first char
158         char_type c = par_.getChar(pos);
159         str += c;
160         ++vpos;
161
162         int const width = theFontMetrics(font).width(c);
163         int dx = 0;
164
165         for (pos_type i = pos - 1; i >= 0; --i) {
166                 c = par_.getChar(i);
167                 if (!Encodings::isComposeChar_hebrew(c)) {
168                         if (isPrintableNonspace(c)) {
169                                 int const width2 = pm_.singleWidth(i,
170                                         text_metrics_.getDisplayFont(pit_, i));
171                                 dx = (c == 0x05e8 || // resh
172                                       c == 0x05d3)   // dalet
173                                         ? width2 - width
174                                         : (width2 - width) / 2;
175                         }
176                         break;
177                 }
178         }
179
180         // Draw nikud
181         pi_.pain.text(int(x_) + dx, yo_, str, font);
182 }
183
184
185 void RowPainter::paintArabicComposeChar(pos_type & vpos, FontInfo const & font)
186 {
187         pos_type pos = bidi_.vis2log(vpos);
188         docstring str;
189
190         // first char
191         char_type c = par_.getChar(pos);
192         c = par_.transformChar(c, pos);
193         str += c;
194         ++vpos;
195
196         int const width = theFontMetrics(font).width(c);
197         int dx = 0;
198
199         for (pos_type i = pos - 1; i >= 0; --i) {
200                 c = par_.getChar(i);
201                 if (!Encodings::isComposeChar_arabic(c)) {
202                         if (isPrintableNonspace(c)) {
203                                 int const width2 = pm_.singleWidth(i,
204                                                 text_metrics_.getDisplayFont(pit_, i));
205                                 dx = (width2 - width) / 2;
206                         }
207                         break;
208                 }
209         }
210         // Draw nikud
211         pi_.pain.text(int(x_) + dx, yo_, str, font);
212 }
213
214
215 void RowPainter::paintChars(pos_type & vpos, FontInfo const & font,
216                             bool hebrew, bool arabic)
217 {
218         // This method takes up 70% of time when typing
219         pos_type pos = bidi_.vis2log(vpos);
220         pos_type const end = row_.endpos();
221         FontSpan const font_span = par_.fontSpan(pos);
222         Change::Type const prev_change = par_.lookupChange(pos).type;
223
224         // first character
225         vector<char_type> str;
226         str.reserve(100);
227         str.push_back(par_.getChar(pos));
228
229         if (arabic) {
230                 char_type c = str[0];
231                 if (c == '(')
232                         c = ')';
233                 else if (c == ')')
234                         c = '(';
235                 str[0] = par_.transformChar(c, pos);
236         }
237
238         // collect as much similar chars as we can
239         for (++vpos ; vpos < end ; ++vpos) {
240                 pos = bidi_.vis2log(vpos);
241                 if (pos < font_span.first || pos > font_span.last)
242                         break;
243
244                 if (prev_change != par_.lookupChange(pos).type)
245                         break;
246
247                 char_type c = par_.getChar(pos);
248
249                 if (!isPrintableNonspace(c))
250                         break;
251
252                 /* Because we do our own bidi, at this point the strings are
253                  * already in visual order. However, Qt also applies its own
254                  * bidi algorithm to strings that it paints to the screen.
255                  * Therefore, if we were to paint Hebrew/Arabic words as a
256                  * single string, the letters in the words would get reversed
257                  * again. In order to avoid that, we don't collect Hebrew/
258                  * Arabic characters, but rather paint them one at a time.
259                  * See also http://thread.gmane.org/gmane.editors.lyx.devel/79740
260                  */
261                 if (hebrew)
262                         break;
263
264                 /* FIXME: these checks are irrelevant, since 'arabic' and
265                  * 'hebrew' alone are already going to trigger a break.
266                  * However, this should not be removed completely, because
267                  * if an alternative solution is found which allows grouping
268                  * of arabic and hebrew characters, then these breaks may have
269                  * to be re-applied.
270
271                 if (arabic && Encodings::isComposeChar_arabic(c))
272                         break;
273
274                 if (hebrew && Encodings::isComposeChar_hebrew(c))
275                         break;
276                 */
277
278                 if (arabic) {
279                         if (c == '(')
280                                 c = ')';
281                         else if (c == ')')
282                                 c = '(';
283                         c = par_.transformChar(c, pos);
284                         /* see comment in hebrew, explaining why we break */
285                         break;
286                 }
287
288                 str.push_back(c);
289         }
290
291         docstring s(&str[0], str.size());
292
293         if (prev_change != Change::UNCHANGED) {
294                 FontInfo copy = font;
295                 if (prev_change == Change::DELETED) {
296                         copy.setColor(Color_deletedtext);
297                 } else if (prev_change == Change::INSERTED) {
298                         copy.setColor(Color_addedtext);
299                 }
300                 x_ += pi_.pain.text(int(x_), yo_, s, copy);
301         } else {
302                 x_ += pi_.pain.text(int(x_), yo_, s, font);
303         }
304 }
305
306
307 void RowPainter::paintForeignMark(double orig_x, Language const * lang,
308                 int desc)
309 {
310         if (!lyxrc.mark_foreign_language)
311                 return;
312         if (lang == latex_language)
313                 return;
314         if (lang == pi_.base.bv->buffer().params().language)
315                 return;
316
317         int const y = yo_ + 1 + desc;
318         pi_.pain.line(int(orig_x), y, int(x_), y, Color_language);
319 }
320
321
322 void RowPainter::paintFromPos(pos_type & vpos)
323 {
324         pos_type const pos = bidi_.vis2log(vpos);
325         Font const orig_font = text_metrics_.getDisplayFont(pit_, pos);
326         double const orig_x = x_;
327
328         // usual characters, no insets
329         char_type const c = par_.getChar(pos);
330
331         // special case languages
332         string const & lang = orig_font.language()->lang();
333         bool const hebrew = lang == "hebrew";
334         bool const arabic = lang == "arabic_arabtex" || lang == "arabic_arabi" || 
335                                                 lang == "farsi";
336
337         // draw as many chars as we can
338         if ((!hebrew && !arabic)
339                 || (hebrew && !Encodings::isComposeChar_hebrew(c))
340                 || (arabic && !Encodings::isComposeChar_arabic(c))) {
341                 paintChars(vpos, orig_font.fontInfo(), hebrew, arabic);
342         } else if (hebrew) {
343                 paintHebrewComposeChar(vpos, orig_font.fontInfo());
344         } else if (arabic) {
345                 paintArabicComposeChar(vpos, orig_font.fontInfo());
346         }
347
348         paintForeignMark(orig_x, orig_font.language());
349 }
350
351
352 void RowPainter::paintChangeBar()
353 {
354         pos_type const start = row_.pos();
355         pos_type end = row_.endpos();
356
357         if (par_.size() == end) {
358                 // this is the last row of the paragraph;
359                 // thus, we must also consider the imaginary end-of-par character
360                 end++;
361         }
362
363         if (start == end || !par_.isChanged(start, end))
364                 return;
365
366         int const height = text_metrics_.isLastRow(pit_, row_)
367                 ? row_.ascent()
368                 : row_.height();
369
370         pi_.pain.fillRectangle(5, yo_ - row_.ascent(), 3, height, Color_changebar);
371 }
372
373
374 void RowPainter::paintAppendix()
375 {
376         // only draw the appendix frame once (for the main text)
377         if (!par_.params().appendix() || !text_.isMainText(pi_.base.bv->buffer()))
378                 return;
379
380         int y = yo_ - row_.ascent();
381
382         if (par_.params().startOfAppendix())
383                 y += 2 * defaultRowHeight();
384
385         pi_.pain.line(1, y, 1, yo_ + row_.height(), Color_appendix);
386         pi_.pain.line(width_ - 2, y, width_ - 2, yo_ + row_.height(), Color_appendix);
387 }
388
389
390 void RowPainter::paintDepthBar()
391 {
392         depth_type const depth = par_.getDepth();
393
394         if (depth <= 0)
395                 return;
396
397         depth_type prev_depth = 0;
398         if (!text_metrics_.isFirstRow(pit_, row_)) {
399                 pit_type pit2 = pit_;
400                 if (row_.pos() == 0)
401                         --pit2;
402                 prev_depth = pars_[pit2].getDepth();
403         }
404
405         depth_type next_depth = 0;
406         if (!text_metrics_.isLastRow(pit_, row_)) {
407                 pit_type pit2 = pit_;
408                 if (row_.endpos() >= pars_[pit2].size())
409                         ++pit2;
410                 next_depth = pars_[pit2].getDepth();
411         }
412
413         for (depth_type i = 1; i <= depth; ++i) {
414                 int const w = nestMargin() / 5;
415                 int x = int(xo_) + w * i;
416                 // only consider the changebar space if we're drawing outermost text
417                 if (text_.isMainText(pi_.base.bv->buffer()))
418                         x += changebarMargin();
419
420                 int const starty = yo_ - row_.ascent();
421                 int const h =  row_.height() - 1 - (i - next_depth - 1) * 3;
422
423                 pi_.pain.line(x, starty, x, starty + h, Color_depthbar);
424
425                 if (i > prev_depth)
426                         pi_.pain.fillRectangle(x, starty, w, 2, Color_depthbar);
427                 if (i > next_depth)
428                         pi_.pain.fillRectangle(x, starty + h, w, 2, Color_depthbar);
429         }
430 }
431
432
433 int RowPainter::paintAppendixStart(int y)
434 {
435         FontInfo pb_font = sane_font;
436         pb_font.setColor(Color_appendix);
437         pb_font.decSize();
438
439         int w = 0;
440         int a = 0;
441         int d = 0;
442
443         docstring const label = _("Appendix");
444         theFontMetrics(pb_font).rectText(label, w, a, d);
445
446         int const text_start = int(xo_ + (width_ - w) / 2);
447         int const text_end = text_start + w;
448
449         pi_.pain.rectText(text_start, y + d, label, pb_font, Color_none, Color_none);
450
451         pi_.pain.line(int(xo_ + 1), y, text_start, y, Color_appendix);
452         pi_.pain.line(text_end, y, int(xo_ + width_ - 2), y, Color_appendix);
453
454         return 3 * defaultRowHeight();
455 }
456
457
458 void RowPainter::paintFirst()
459 {
460         ParagraphParameters const & parparams = par_.params();
461
462         int y_top = 0;
463
464         // start of appendix?
465         if (parparams.startOfAppendix())
466                 y_top += paintAppendixStart(yo_ - row_.ascent() + 2 * defaultRowHeight());
467
468         Buffer const & buffer = pi_.base.bv->buffer();
469
470         LayoutPtr const & layout = par_.layout();
471
472         if (buffer.params().paragraph_separation == BufferParams::PARSEP_SKIP) {
473                 if (pit_ != 0) {
474                         if (layout->latextype == LATEX_PARAGRAPH
475                                 && !par_.getDepth()) {
476                                 y_top += buffer.params().getDefSkip().inPixels(*pi_.base.bv);
477                         } else {
478                                 LayoutPtr const & playout = pars_[pit_ - 1].layout();
479                                 if (playout->latextype == LATEX_PARAGRAPH
480                                         && !pars_[pit_ - 1].getDepth()) {
481                                         // is it right to use defskip here, too? (AS)
482                                         y_top += buffer.params().getDefSkip().inPixels(*pi_.base.bv);
483                                 }
484                         }
485                 }
486         }
487
488         bool const is_rtl = text_.isRTL(buffer, par_);
489         bool const is_seq = isFirstInSequence(pit_, text_.paragraphs());
490         //lyxerr << "paintFirst: " << par_.id() << " is_seq: " << is_seq << endl;
491
492         // should we print a label?
493         if (layout->labeltype >= LABEL_STATIC
494             && (layout->labeltype != LABEL_STATIC
495                       || layout->latextype != LATEX_ENVIRONMENT
496                       || is_seq)) {
497
498                 FontInfo const font = getLabelFont();
499                 FontMetrics const & fm = theFontMetrics(font);
500
501                 docstring const str = par_.getLabelstring();
502                 if (!str.empty()) {
503                         double x = x_;
504
505                         // this is special code for the chapter layout. This is
506                         // printed in an extra row and has a pagebreak at
507                         // the top.
508                         if (layout->counter == "chapter") {
509                                 double spacing_val = 1.0;
510                                 if (!parparams.spacing().isDefault()) {
511                                         spacing_val = parparams.spacing().getValue();
512                                 } else {
513                                         spacing_val = buffer.params().spacing().getValue();
514                                 }
515
516                                 int const labeladdon = int(fm.maxHeight() * layout->spacing.getValue() * spacing_val);
517
518                                 int const maxdesc = int(fm.maxDescent() * layout->spacing.getValue() * spacing_val)
519                                         + int(layout->parsep) * defaultRowHeight();
520
521                                 if (is_rtl) {
522                                         x = width_ - leftMargin() -
523                                                 fm.width(str);
524                                 }
525
526                                 pi_.pain.text(int(x), yo_ - maxdesc - labeladdon, str, font);
527                         } else {
528                                 if (is_rtl) {
529                                         x = width_ - leftMargin()
530                                                 + fm.width(layout->labelsep);
531                                 } else {
532                                         x = x_ - fm.width(layout->labelsep)
533                                                 - fm.width(str);
534                                 }
535
536                                 pi_.pain.text(int(x), yo_, str, font);
537                         }
538                 }
539
540         // the labels at the top of an environment.
541         // More or less for bibliography
542         } else if (is_seq &&
543                 (layout->labeltype == LABEL_TOP_ENVIRONMENT ||
544                 layout->labeltype == LABEL_BIBLIO ||
545                 layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)) {
546                 FontInfo const font = getLabelFont();
547                 if (!par_.getLabelstring().empty()) {
548                         docstring const str = par_.getLabelstring();
549                         double spacing_val = 1.0;
550                         if (!parparams.spacing().isDefault())
551                                 spacing_val = parparams.spacing().getValue();
552                         else
553                                 spacing_val = buffer.params().spacing().getValue();
554
555                         FontMetrics const & fm = theFontMetrics(font);
556
557                         int const labeladdon = int(fm.maxHeight()
558                                 * layout->spacing.getValue() * spacing_val);
559
560                         int maxdesc =
561                                 int(fm.maxDescent() * layout->spacing.getValue() * spacing_val
562                                 + (layout->labelbottomsep * defaultRowHeight()));
563
564                         double x = x_;
565                         if (layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
566                                 if (is_rtl)
567                                         x = leftMargin();
568                                 x += (width_ - text_metrics_.rightMargin(pm_) - leftMargin()) / 2;
569                                 x -= fm.width(str) / 2;
570                         } else if (is_rtl) {
571                                 x = width_ - leftMargin() -     fm.width(str);
572                         }
573                         pi_.pain.text(int(x), yo_ - maxdesc - labeladdon, str, font);
574                 }
575         }
576 }
577
578
579 void RowPainter::paintLast()
580 {
581         bool const is_rtl = text_.isRTL(pi_.base.bv->buffer(), par_);
582         int const endlabel = getEndLabel(pit_, text_.paragraphs());
583
584         // paint imaginary end-of-paragraph character
585
586         if (par_.isInserted(par_.size()) || par_.isDeleted(par_.size())) {
587                 FontMetrics const & fm = theFontMetrics(pi_.base.bv->buffer().params().getFont());
588                 int const length = fm.maxAscent() / 2;
589                 ColorCode col = par_.isInserted(par_.size()) ? Color_addedtext : Color_deletedtext;
590
591                 pi_.pain.line(int(x_) + 1, yo_ + 2, int(x_) + 1, yo_ + 2 - length, col,
592                            Painter::line_solid, Painter::line_thick);
593                 pi_.pain.line(int(x_) + 1 - length, yo_ + 2, int(x_) + 1, yo_ + 2, col,
594                            Painter::line_solid, Painter::line_thick);
595         }
596
597         // draw an endlabel
598
599         switch (endlabel) {
600         case END_LABEL_BOX:
601         case END_LABEL_FILLED_BOX: {
602                 FontInfo const font = getLabelFont();
603                 FontMetrics const & fm = theFontMetrics(font);
604                 int const size = int(0.75 * fm.maxAscent());
605                 int const y = yo_ - size;
606                 int x = is_rtl ? nestMargin() + changebarMargin() : width_ - size;
607
608                 if (width_ - int(row_.width()) <= size)
609                         x += (size - width_ + row_.width() + 1) * (is_rtl ? -1 : 1);
610
611                 if (endlabel == END_LABEL_BOX)
612                         pi_.pain.rectangle(x, y, size, size, Color_eolmarker);
613                 else
614                         pi_.pain.fillRectangle(x, y, size, size, Color_eolmarker);
615                 break;
616         }
617
618         case END_LABEL_STATIC: {
619                 FontInfo const font = getLabelFont();
620                 FontMetrics const & fm = theFontMetrics(font);
621                 docstring const & str = par_.layout()->endlabelstring();
622                 double const x = is_rtl ?
623                         x_ - fm.width(str)
624                         : - text_metrics_.rightMargin(pm_) - row_.width();
625                 pi_.pain.text(int(x), yo_, str, font);
626                 break;
627         }
628
629         case END_LABEL_NO_LABEL:
630                 break;
631         }
632 }
633
634
635 void RowPainter::paintOnlyInsets()
636 {
637         pos_type const end = row_.endpos();
638         for (pos_type pos = row_.pos(); pos != end; ++pos) {
639                 if (!par_.isInset(pos))
640                         continue;
641
642                 // If outer row has changed, nested insets are repaint completely.
643                 Inset const * inset = par_.getInset(pos);
644
645                 if (x_ > pi_.base.bv->workWidth())
646                         continue;
647
648                 x_ = pi_.base.bv->coordCache().getInsets().x(inset);
649                 paintInset(inset, pos);
650         }
651 }
652
653
654 void RowPainter::paintText()
655 {
656         pos_type const end = row_.endpos();
657         // Spaces at logical line breaks in bidi text must be skipped during 
658         // painting. However, they may appear visually in the middle
659         // of a row; they must be skipped, wherever they are...
660         // * logically "abc_[HEBREW_\nHEBREW]"
661         // * visually "abc_[_WERBEH\nWERBEH]"
662         pos_type skipped_sep_vpos = -1;
663         pos_type body_pos = par_.beginOfBody();
664         if (body_pos > 0 &&
665                 (body_pos > end || !par_.isLineSeparator(body_pos - 1))) {
666                 body_pos = 0;
667         }
668
669         LayoutPtr const & layout = par_.layout();
670
671         bool running_strikeout = false;
672         bool is_struckout = false;
673         int last_strikeout_x = 0;
674
675         // Use font span to speed things up, see below
676         FontSpan font_span;
677         Font font;
678
679         // If the last logical character is a separator, don't paint it, unless
680         // it's in the last row of a paragraph; see skipped_sep_vpos declaration
681         if (end > 0 && end < par_.size() && par_.isSeparator(end - 1))
682                 skipped_sep_vpos = bidi_.log2vis(end - 1);
683         
684         for (pos_type vpos = row_.pos(); vpos < end; ) {
685                 if (x_ > pi_.base.bv->workWidth())
686                         break;
687
688                 // Skip the separator at the logical end of the row
689                 if (vpos == skipped_sep_vpos) {
690                         ++vpos;
691                         continue;
692                 }
693
694                 pos_type const pos = bidi_.vis2log(vpos);
695
696                 if (pos >= par_.size()) {
697                         ++vpos;
698                         continue;
699                 }
700
701                 // Use font span to speed things up, see above
702                 if (vpos < font_span.first || vpos > font_span.last) {
703                         font_span = par_.fontSpan(vpos);
704                         font = text_metrics_.getDisplayFont(pit_, vpos);
705                 }
706
707                 const int width_pos = pm_.singleWidth(pos, font);
708
709                 if (x_ + width_pos < 0) {
710                         x_ += width_pos;
711                         ++vpos;
712                         continue;
713                 }
714
715                 is_struckout = par_.isDeleted(pos);
716
717                 if (is_struckout && !running_strikeout) {
718                         running_strikeout = true;
719                         last_strikeout_x = int(x_);
720                 }
721
722                 bool const highly_editable_inset = par_.isInset(pos)
723                         && par_.getInset(pos)->editable() == Inset::HIGHLY_EDITABLE;
724
725                 // If we reach the end of a struck out range, paint it.
726                 // We also don't paint across things like tables
727                 if (running_strikeout && (highly_editable_inset || !is_struckout)) {
728                         // Calculate 1/3 height of the buffer's default font
729                         FontMetrics const & fm
730                                 = theFontMetrics(pi_.base.bv->buffer().params().getFont());
731                         int const middle = yo_ - fm.maxAscent() / 3;
732                         pi_.pain.line(last_strikeout_x, middle, int(x_), middle,
733                                 Color_deletedtext, Painter::line_solid, Painter::line_thin);
734                         running_strikeout = false;
735                 }
736
737                 if (body_pos > 0 && pos == body_pos - 1) {
738                         int const lwidth = theFontMetrics(getLabelFont())
739                                 .width(layout->labelsep);
740
741                         x_ += row_.label_hfill + lwidth - width_pos;
742                 }
743
744                 if (par_.isSeparator(pos)) {
745                         Font const orig_font = text_metrics_.getDisplayFont(pit_, pos);
746                         double const orig_x = x_;
747                         x_ += width_pos;
748                         if (pos >= body_pos)
749                                 x_ += row_.separator;
750                         paintForeignMark(orig_x, orig_font.language());
751                         ++vpos;
752
753                 } else if (par_.isInset(pos)) {
754                         // If outer row has changed, nested insets are repaint completely.
755                         Inset const * inset = par_.getInset(pos);
756                         pi_.base.bv->coordCache().insets().add(inset, int(x_), yo_);
757                         paintInset(inset, pos);
758                         ++vpos;
759
760                 } else {
761                         // paint as many characters as possible.
762                         paintFromPos(vpos);
763                 }
764         }
765
766         // if we reach the end of a struck out range, paint it
767         if (running_strikeout) {
768                 // calculate 1/3 height of the buffer's default font
769                 FontMetrics const & fm
770                         = theFontMetrics(pi_.base.bv->buffer().params().getFont());
771                 int const middle = yo_ - fm.maxAscent() / 3;
772                 pi_.pain.line(last_strikeout_x, middle, int(x_), middle,
773                         Color_deletedtext, Painter::line_solid, Painter::line_thin);
774                 running_strikeout = false;
775         }
776 }
777
778 } // namespace lyx