3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
14 #include "rowpainter.h"
18 #include "bufferparams.h"
19 #include "BufferView.h"
26 #include "lyxrow_funcs.h"
27 #include "metricsinfo.h"
28 #include "paragraph.h"
29 #include "paragraph_funcs.h"
30 #include "ParagraphParameters.h"
33 #include "frontends/font_metrics.h"
34 #include "frontends/Painter.h"
36 #include "insets/insettext.h"
38 #include "support/textutils.h"
45 extern int PAPER_MARGIN;
46 extern int CHANGEBAR_MARGIN;
47 extern int LEFT_MARGIN;
51 // "temporary". We'll never get to use more
52 // references until we start adding hacks like
53 // these until other places catch up.
54 BufferView * perv(BufferView const & bv)
56 return const_cast<BufferView *>(&bv);
60 * A class used for painting an individual row of text.
64 /// initialise painter
65 RowPainter(BufferView const & bv, LyXText const & text,
66 ParagraphList::iterator pit,
67 RowList::iterator rit, int y_offset, int x_offset, int y);
72 // paint various parts
73 void paintBackground();
74 void paintSelection();
77 void paintChangeBar();
80 void paintForeignMark(double orig_x, LyXFont const & orig_font);
81 void paintHebrewComposeChar(lyx::pos_type & vpos);
82 void paintArabicComposeChar(lyx::pos_type & vpos);
83 void paintChars(lyx::pos_type & vpos, bool hebrew, bool arabic);
84 int paintPageBreak(string const & label, int y);
85 int paintAppendixStart(int y);
86 int paintLengthMarker(string const & prefix, VSpace const & vsp, int start);
88 void paintFromPos(lyx::pos_type & vpos);
89 void paintInset(lyx::pos_type const pos);
91 /// return left margin
92 int leftMargin() const;
94 /// return the font at the given pos
95 LyXFont const getFont(lyx::pos_type pos) const;
97 /// return the label font for this row
98 LyXFont const getLabelFont() const;
100 char const transformChar(char c, lyx::pos_type pos) const;
102 /// return pixel width for the given pos
103 int singleWidth(lyx::pos_type pos) const;
104 int singleWidth(lyx::pos_type pos, char c) const;
106 /// bufferview to paint on
107 BufferView const & bv_;
112 /// LyXText for the row
113 LyXText const & text_;
116 RowList::iterator const rit_;
120 mutable ParagraphList::iterator pit_;
134 RowPainter::RowPainter(BufferView const & bv, LyXText const & text,
135 ParagraphList::iterator pit, RowList::iterator rit,
136 int y_offset, int x_offset, int y)
137 : bv_(bv), pain_(bv_.painter()), text_(text), rit_(rit), row_(*rit),
138 pit_(pit), xo_(x_offset), yo_(y_offset), y_(y)
143 LyXFont const RowPainter::getFont(pos_type pos) const
145 return text_.getFont(pit_, pos);
149 int RowPainter::singleWidth(lyx::pos_type pos) const
151 return text_.singleWidth(pit_, pos);
155 int RowPainter::singleWidth(lyx::pos_type pos, char c) const
157 LyXFont const & font = text_.getFont(pit_, pos);
158 return text_.singleWidth(pit_, pos, c, font);
162 LyXFont const RowPainter::getLabelFont() const
164 return text_.getLabelFont(pit_);
168 char const RowPainter::transformChar(char c, lyx::pos_type pos) const
170 return text_.transformChar(c, *pit_, pos);
174 int RowPainter::leftMargin() const
176 return text_.leftMargin(pit_, row_);
180 void RowPainter::paintInset(pos_type const pos)
182 InsetOld * inset = const_cast<InsetOld*>(pit_->getInset(pos));
186 PainterInfo pi(perv(bv_));
187 pi.base.font = getFont(pos);
188 inset->draw(pi, int(x_), yo_ + row_.baseline());
189 x_ += inset->width();
193 void RowPainter::paintHebrewComposeChar(pos_type & vpos)
195 pos_type pos = text_.bidi.vis2log(vpos);
200 char c = pit_->getChar(pos);
204 LyXFont const & font = getFont(pos);
205 int const width = font_metrics::width(c, font);
208 for (pos_type i = pos - 1; i >= 0; --i) {
209 c = pit_->getChar(i);
210 if (!Encodings::IsComposeChar_hebrew(c)) {
211 if (IsPrintableNonspace(c)) {
212 int const width2 = singleWidth(i, c);
214 dx = (c == 'ø' || c == 'ã')
216 : (width2 - width) / 2;
223 pain_.text(int(x_) + dx, yo_ + row_.baseline(), str, font);
227 void RowPainter::paintArabicComposeChar(pos_type & vpos)
229 pos_type pos = text_.bidi.vis2log(vpos);
233 char c = pit_->getChar(pos);
234 c = transformChar(c, pos);
238 LyXFont const & font = getFont(pos);
239 int const width = font_metrics::width(c, font);
242 for (pos_type i = pos - 1; i >= 0; --i) {
243 c = pit_->getChar(i);
244 if (!Encodings::IsComposeChar_arabic(c)) {
245 if (IsPrintableNonspace(c)) {
246 int const width2 = singleWidth(i, c);
247 dx = (width2 - width) / 2;
253 pain_.text(int(x_) + dx, yo_ + row_.baseline(), str, font);
257 void RowPainter::paintChars(pos_type & vpos, bool hebrew, bool arabic)
259 pos_type pos = text_.bidi.vis2log(vpos);
260 pos_type const last = lastPos(*pit_, row_);
261 LyXFont orig_font = getFont(pos);
265 str += pit_->getChar(pos);
267 unsigned char c = str[0];
268 str[0] = transformChar(c, pos);
271 bool prev_struckout = isDeletedText(*pit_, pos);
272 bool prev_newtext = isInsertedText(*pit_, pos);
276 // collect as much similar chars as we can
277 while (vpos <= last && (pos = text_.bidi.vis2log(vpos)) >= 0) {
278 char c = pit_->getChar(pos);
280 if (!IsPrintableNonspace(c))
283 if (prev_struckout != isDeletedText(*pit_, pos))
286 if (prev_newtext != isInsertedText(*pit_, pos))
289 if (arabic && Encodings::IsComposeChar_arabic(c))
292 if (hebrew && Encodings::IsComposeChar_hebrew(c))
295 if (orig_font != getFont(pos))
299 c = transformChar(c, pos);
304 if (prev_struckout) {
305 orig_font.setColor(LColor::strikeout);
306 } else if (prev_newtext) {
307 orig_font.setColor(LColor::newtext);
310 // Draw text and set the new x position
311 //lyxerr << "paint row: yo_ " << yo_ << " baseline: " << row_.baseline()
313 pain_.text(int(x_), yo_ + row_.baseline(), str, orig_font);
314 x_ += font_metrics::width(str, orig_font);
318 void RowPainter::paintForeignMark(double orig_x, LyXFont const & orig_font)
320 if (!lyxrc.mark_foreign_language)
322 if (orig_font.language() == latex_language)
324 if (orig_font.language() == bv_.buffer()->params().language)
327 int const y = yo_ + row_.baseline() + 1;
328 pain_.line(int(orig_x), y, int(x_), y, LColor::language);
332 void RowPainter::paintFromPos(pos_type & vpos)
334 pos_type const pos = text_.bidi.vis2log(vpos);
336 LyXFont const & orig_font = getFont(pos);
338 double const orig_x = x_;
340 char const c = pit_->getChar(pos);
342 if (c == Paragraph::META_INSET) {
345 paintForeignMark(orig_x, orig_font);
349 // usual characters, no insets
351 // special case languages
352 bool const hebrew = (orig_font.language()->lang() == "hebrew");
354 orig_font.language()->lang() == "arabic" &&
355 (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
356 lyxrc.font_norm_type == LyXRC::ISO_10646_1);
358 // draw as many chars as we can
359 if ((!hebrew && !arabic)
360 || (hebrew && !Encodings::IsComposeChar_hebrew(c))
361 || (arabic && !Encodings::IsComposeChar_arabic(c))) {
362 paintChars(vpos, hebrew, arabic);
364 paintHebrewComposeChar(vpos);
366 paintArabicComposeChar(vpos);
369 paintForeignMark(orig_x, orig_font);
375 void RowPainter::paintBackground()
377 int const x = int(xo_);
378 int const y = yo_ < 0 ? 0 : yo_;
379 int const h = yo_ < 0 ? row_.height() + yo_ : row_.height();
380 pain_.fillRectangle(x, y, width_, h, text_.backgroundColor());
384 void RowPainter::paintSelection()
386 bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params());
388 // the current selection
389 int const startx = text_.selection.start.x();
390 int const endx = text_.selection.end.x();
391 int const starty = text_.selection.start.y();
392 int const endy = text_.selection.end.y();
393 ParagraphList::iterator startpit = text_.getPar(text_.selection.start);
394 ParagraphList::iterator endpit = text_.getPar(text_.selection.end);
395 RowList::iterator startrow = startpit->getRow(text_.selection.start.pos());
396 RowList::iterator endrow = endpit->getRow(text_.selection.end.pos());
398 if (text_.bidi.same_direction()) {
402 int h = row_.height();
404 if (startrow == rit_ && endrow == rit_) {
406 x = int(xo_) + startx;
408 pain_.fillRectangle(x, y, w, h, LColor::selection);
412 pain_.fillRectangle(x, y, w, h, LColor::selection);
414 } else if (startrow == rit_) {
415 int const x = is_rtl ? int(xo_) : int(xo_ + startx);
416 int const w = is_rtl ? startx : (width_ - startx);
417 pain_.fillRectangle(x, y, w, h, LColor::selection);
418 } else if (endrow == rit_) {
419 int const x = is_rtl ? int(xo_ + endx) : int(xo_);
420 int const w = is_rtl ? (width_ - endx) : endx;
421 pain_.fillRectangle(x, y, w, h, LColor::selection);
422 } else if (y_ > starty && y_ < endy) {
423 pain_.fillRectangle(int(xo_), y, width_, h, LColor::selection);
426 } else if (startrow != rit_ && endrow != rit_) {
427 if (y_ > starty && y_ < endy) {
429 int h = row_.height();
430 pain_.fillRectangle(int(xo_), yo_, w, h, LColor::selection);
435 if ((startrow != rit_ && !is_rtl) || (endrow != rit_ && is_rtl))
436 pain_.fillRectangle(int(xo_), yo_,
437 int(x_), row_.height(), LColor::selection);
439 pos_type const body_pos = pit_->beginningOfBody();
440 pos_type const last = lastPos(*pit_, row_);
443 for (pos_type vpos = row_.pos(); vpos <= last; ++vpos) {
444 pos_type pos = text_.bidi.vis2log(vpos);
445 double const old_tmpx = tmpx;
446 if (body_pos > 0 && pos == body_pos - 1) {
447 LyXLayout_ptr const & layout = pit_->layout();
448 LyXFont const lfont = getLabelFont();
450 tmpx += label_hfill_ + font_metrics::width(layout->labelsep, lfont);
452 if (pit_->isLineSeparator(body_pos - 1))
453 tmpx -= singleWidth(body_pos - 1);
456 if (hfillExpansion(*pit_, row_, pos)) {
457 tmpx += singleWidth(pos);
461 tmpx += label_hfill_;
464 else if (pit_->isSeparator(pos)) {
465 tmpx += singleWidth(pos);
469 tmpx += singleWidth(pos);
472 if ((startrow != rit_ || text_.selection.start.pos() <= pos) &&
473 (endrow != rit_ || pos < text_.selection.end.pos())) {
474 // Here we do not use x_ as xo_ was added to x_.
475 pain_.fillRectangle(int(old_tmpx), yo_,
476 int(tmpx - old_tmpx + 1),
477 row_.height(), LColor::selection);
481 if ((startrow != rit_ && is_rtl) || (endrow != rit_ && !is_rtl)) {
482 pain_.fillRectangle(int(xo_ + tmpx),
483 yo_, int(bv_.workWidth() - tmpx),
484 row_.height(), LColor::selection);
489 void RowPainter::paintChangeBar()
491 pos_type const start = row_.pos();
492 pos_type const end = lastPos(*pit_, row_);
494 if (!pit_->isChanged(start, end))
497 int const height = text_.isLastRow(pit_, row_)
499 : row_.height() + boost::next(rit_)->top_of_text();
501 pain_.fillRectangle(4, yo_, 5, height, LColor::changebar);
505 void RowPainter::paintAppendix()
507 if (!pit_->params().appendix())
510 // FIXME: can be just width_ ?
511 int const ww = bv_.workWidth();
515 if (pit_->params().startOfAppendix())
516 y += 2 * defaultRowHeight();
518 pain_.line(1, y, 1, yo_ + row_.height(), LColor::appendix);
519 pain_.line(ww - 2, y, ww - 2, yo_ + row_.height(), LColor::appendix);
523 void RowPainter::paintDepthBar()
525 Paragraph::depth_type const depth = pit_->getDepth();
530 Paragraph::depth_type prev_depth = 0;
531 if (!text_.isFirstRow(pit_, row_)) {
532 ParagraphList::iterator pit2 = pit_;
535 prev_depth = pit2->getDepth();
538 Paragraph::depth_type next_depth = 0;
539 if (!text_.isLastRow(pit_, row_)) {
540 ParagraphList::iterator pit2 = pit_;
541 if (row_.endpos() >= pit2->size())
543 next_depth = pit2->getDepth();
546 for (Paragraph::depth_type i = 1; i <= depth; ++i) {
547 int const w = PAPER_MARGIN / 5;
548 int x = int(w * i + xo_);
549 // only consider the changebar space if we're drawing outer left
551 x += CHANGEBAR_MARGIN;
552 int const h = yo_ + row_.height() - 1 - (i - next_depth - 1) * 3;
554 pain_.line(x, yo_, x, h, LColor::depthbar);
557 pain_.fillRectangle(x, yo_, w, 2, LColor::depthbar);
559 pain_.fillRectangle(x, h, w, 2, LColor::depthbar);
564 int RowPainter::paintLengthMarker(string const & prefix, VSpace const & vsp, int start)
566 if (vsp.kind() == VSpace::NONE)
569 int const arrow_size = 4;
570 int const size = getLengthMarkerHeight(bv_, vsp);
571 int const end = start + size;
573 // the label to display (if any)
575 // y-values for top arrow
577 // y-values for bottom arrow
580 str = prefix + " (" + vsp.asLyXCommand() + ")";
582 if (vsp.kind() == VSpace::VFILL) {
586 // adding or removing space
587 bool const added = vsp.kind() != VSpace::LENGTH ||
588 vsp.length().len().value() > 0.0;
589 ty1 = added ? (start + arrow_size) : start;
590 ty2 = added ? start : (start + arrow_size);
591 by1 = added ? (end - arrow_size) : end;
592 by2 = added ? end : (end - arrow_size);
595 int const leftx = int(xo_) + leftMargin();
596 int const midx = leftx + arrow_size;
597 int const rightx = midx + arrow_size;
605 font.setColor(LColor::added_space);
608 font_metrics::rectText(str, font, w, a, d);
610 pain_.rectText(leftx + 2 * arrow_size + 5,
611 start + ((end - start) / 2) + d,
613 LColor::none, LColor::none);
616 pain_.line(leftx, ty1, midx, ty2, LColor::added_space);
617 pain_.line(midx, ty2, rightx, ty1, LColor::added_space);
620 pain_.line(leftx, by1, midx, by2, LColor::added_space);
621 pain_.line(midx, by2, rightx, by1, LColor::added_space);
624 pain_.line(midx, ty2, midx, by2, LColor::added_space);
630 int RowPainter::paintPageBreak(string const & label, int y)
633 pb_font.setColor(LColor::pagebreak);
639 font_metrics::rectText(label, pb_font, w, a, d);
641 int const text_start = int(xo_ + (width_ - w) / 2);
642 int const text_end = text_start + w;
644 pain_.rectText(text_start, y + d, label, pb_font, LColor::none, LColor::none);
646 pain_.line(int(xo_), y, text_start, y,
647 LColor::pagebreak, Painter::line_onoffdash);
648 pain_.line(text_end, y, int(xo_ + width_), y,
649 LColor::pagebreak, Painter::line_onoffdash);
651 return 3 * defaultRowHeight();
655 int RowPainter::paintAppendixStart(int y)
658 pb_font.setColor(LColor::appendix);
661 string const label = _("Appendix");
665 font_metrics::rectText(label, pb_font, w, a, d);
667 int const text_start = int(xo_ + (width_ - w) / 2);
668 int const text_end = text_start + w;
670 pain_.rectText(text_start, y + d, label, pb_font, LColor::none, LColor::none);
672 pain_.line(int(xo_ + 1), y, text_start, y, LColor::appendix);
673 pain_.line(text_end, y, int(xo_ + width_ - 2), y, LColor::appendix);
675 return 3 * defaultRowHeight();
679 void RowPainter::paintFirst()
681 ParagraphParameters const & parparams = pit_->params();
685 // start of appendix?
686 if (parparams.startOfAppendix())
687 y_top += paintAppendixStart(yo_ + y_top + 2 * defaultRowHeight());
690 if (text_.isFirstRow(pit_, row_) && !text_.isInInset())
691 y_top += PAPER_MARGIN;
693 // draw a top pagebreak
694 if (parparams.pagebreakTop())
695 y_top += paintPageBreak(_("Page Break (top)"),
696 yo_ + y_top + 2 * defaultRowHeight());
698 // draw the additional space if needed:
699 y_top += paintLengthMarker(_("Space above"), parparams.spaceTop(),
702 Buffer const & buffer = *bv_.buffer();
704 LyXLayout_ptr const & layout = pit_->layout();
706 if (buffer.params().paragraph_separation == BufferParams::PARSEP_SKIP) {
707 if (pit_ != text_.ownerParagraphs().begin()) {
708 if (layout->latextype == LATEX_PARAGRAPH
709 && !pit_->getDepth()) {
710 y_top += buffer.params().getDefSkip().inPixels(bv_);
712 LyXLayout_ptr const & playout =
713 boost::prior(pit_)->layout();
714 if (playout->latextype == LATEX_PARAGRAPH
715 && !boost::prior(pit_)->getDepth()) {
716 // is it right to use defskip here, too? (AS)
717 y_top += buffer.params().getDefSkip().inPixels(bv_);
723 int const ww = bv_.workWidth();
726 if (parparams.lineTop()) {
727 int const asc = font_metrics::ascent('x', getFont(0));
731 int const w = (text_.isInInset() ? text_.inset_owner->width() : ww);
732 int const xp = static_cast<int>(text_.isInInset() ? xo_ : 0);
733 pain_.line(xp, yo_ + y_top, xp + w, yo_ + y_top,
734 LColor::topline, Painter::line_solid,
735 Painter::line_thick);
740 bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params());
741 bool const is_seq = isFirstInSequence(pit_, text_.ownerParagraphs());
742 //lyxerr << "paintFirst: " << pit_->id() << " is_seq: " << is_seq << std::endl;
744 // should we print a label?
745 if (layout->labeltype >= LABEL_STATIC
746 && (layout->labeltype != LABEL_STATIC
747 || layout->latextype != LATEX_ENVIRONMENT
750 LyXFont font = getLabelFont();
751 if (!pit_->getLabelstring().empty()) {
753 string const str = pit_->getLabelstring();
755 // this is special code for the chapter layout. This is
756 // printed in an extra row and has a pagebreak at
758 if (layout->counter == "chapter") {
759 if (buffer.params().secnumdepth >= 0) {
760 float spacing_val = 1.0;
761 if (!parparams.spacing().isDefault()) {
762 spacing_val = parparams.spacing().getValue();
764 spacing_val = buffer.params().spacing().getValue();
768 int(font_metrics::maxDescent(font) * layout->spacing.getValue() * spacing_val)
769 + int(layout->parsep) * defaultRowHeight();
772 x = ww - leftMargin() -
773 font_metrics::width(str, font);
777 yo_ + row_.baseline() -
778 row_.ascent_of_text() - maxdesc,
783 x = ww - leftMargin()
784 + font_metrics::width(layout->labelsep, font);
786 x = x_ - font_metrics::width(layout->labelsep, font)
787 - font_metrics::width(str, font);
790 pain_.text(int(x), yo_ + row_.baseline(), str, font);
794 // the labels at the top of an environment.
795 // More or less for bibliography
797 (layout->labeltype == LABEL_TOP_ENVIRONMENT ||
798 layout->labeltype == LABEL_BIBLIO ||
799 layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)) {
800 LyXFont font = getLabelFont();
801 if (!pit_->getLabelstring().empty()) {
802 string const str = pit_->getLabelstring();
803 float spacing_val = 1.0;
804 if (!parparams.spacing().isDefault()) {
805 spacing_val = parparams.spacing().getValue();
807 spacing_val = buffer.params().spacing().getValue();
811 int(font_metrics::maxDescent(font) * layout->spacing.getValue() * spacing_val
812 + (layout->labelbottomsep * defaultRowHeight()));
815 if (layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
816 x = ((is_rtl ? leftMargin() : x_)
817 + ww - text_.rightMargin(*pit_, *bv_.buffer(), row_)) / 2;
818 x -= font_metrics::width(str, font) / 2;
820 x = ww - leftMargin() -
821 font_metrics::width(str, font);
824 yo_ + row_.baseline() - row_.ascent_of_text() - maxdesc,
831 void RowPainter::paintLast()
833 ParagraphParameters const & parparams = pit_->params();
834 int y_bottom = row_.height() - 1;
837 if (text_.isLastRow(pit_, row_) && !text_.isInInset())
838 y_bottom -= PAPER_MARGIN;
840 int const ww = bv_.workWidth();
842 // draw a bottom pagebreak
843 if (parparams.pagebreakBottom()) {
844 y_bottom -= paintPageBreak(_("Page Break (bottom)"),
845 yo_ + y_bottom - 2 * defaultRowHeight());
848 // draw the additional space if needed:
849 int const height = getLengthMarkerHeight(bv_, parparams.spaceBottom());
850 y_bottom -= paintLengthMarker(_("Space below"), parparams.spaceBottom(),
851 yo_ + y_bottom - height);
853 // draw a bottom line
854 if (parparams.lineBottom()) {
855 int const asc = font_metrics::ascent('x',
856 getFont(max(pos_type(0), pit_->size() - 1)));
860 int const w = text_.isInInset() ? text_.inset_owner->width() : ww;
861 int const xp = int(text_.isInInset() ? xo_ : 0);
862 int const y = yo_ + y_bottom;
863 pain_.line(xp, y, xp + w, y, LColor::topline, Painter::line_solid,
864 Painter::line_thick);
869 bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params());
870 int const endlabel = getEndLabel(pit_, text_.ownerParagraphs());
875 case END_LABEL_FILLED_BOX:
877 LyXFont const font = getLabelFont();
878 int const size = int(0.75 * font_metrics::maxAscent(font));
879 int const y = (yo_ + row_.baseline()) - size;
880 int x = is_rtl ? LEFT_MARGIN : ww - PAPER_MARGIN - size;
882 if (row_.fill() <= size)
883 x += (size - row_.fill() + 1) * (is_rtl ? -1 : 1);
885 if (endlabel == END_LABEL_BOX)
886 pain_.rectangle(x, y, size, size, LColor::eolmarker);
888 pain_.fillRectangle(x, y, size, size, LColor::eolmarker);
891 case END_LABEL_STATIC:
893 LyXFont font = getLabelFont();
894 string const & str = pit_->layout()->endlabelstring();
895 double const x = is_rtl ?
896 x_ - font_metrics::width(str, font)
897 : ww - text_.rightMargin(*pit_, *bv_.buffer(), row_) - row_.fill();
898 pain_.text(int(x), yo_ + row_.baseline(), str, font);
901 case END_LABEL_NO_LABEL:
907 void RowPainter::paintText()
909 pos_type const last = lastPos(*pit_, row_);
910 pos_type body_pos = pit_->beginningOfBody();
912 (body_pos - 1 > last || !pit_->isLineSeparator(body_pos - 1))) {
916 LyXLayout_ptr const & layout = pit_->layout();
918 bool running_strikeout = false;
919 bool is_struckout = false;
920 int last_strikeout_x = 0;
922 pos_type vpos = row_.pos();
923 while (vpos <= last) {
924 if (x_ > bv_.workWidth())
926 pos_type pos = text_.bidi.vis2log(vpos);
928 if (pos >= pit_->size()) {
933 if (x_ + singleWidth(pos) < 0) {
934 x_ += singleWidth(pos);
939 is_struckout = isDeletedText(*pit_, pos);
941 if (is_struckout && !running_strikeout) {
942 running_strikeout = true;
943 last_strikeout_x = int(x_);
946 bool const highly_editable_inset = pit_->isInset(pos)
947 && isHighlyEditableInset(pit_->getInset(pos));
949 // if we reach the end of a struck out range, paint it
950 // we also don't paint across things like tables
951 if (running_strikeout && (highly_editable_inset || !is_struckout)) {
952 int const middle = yo_ + row_.top_of_text()
953 + (row_.baseline() - row_.top_of_text()) / 2;
954 pain_.line(last_strikeout_x, middle, int(x_), middle,
955 LColor::strikeout, Painter::line_solid, Painter::line_thin);
956 running_strikeout = false;
959 if (body_pos > 0 && pos == body_pos - 1) {
960 int const lwidth = font_metrics::width(layout->labelsep,
963 x_ += label_hfill_ + lwidth - singleWidth(body_pos - 1);
966 if (pit_->isHfill(pos)) {
969 int const y0 = yo_ + row_.baseline();
970 int const y1 = y0 - defaultRowHeight() / 2;
972 pain_.line(int(x_), y1, int(x_), y0, LColor::added_space);
974 if (hfillExpansion(*pit_, row_, pos)) {
975 int const y2 = (y0 + y1) / 2;
977 if (pos >= body_pos) {
978 pain_.line(int(x_), y2, int(x_ + hfill_), y2,
980 Painter::line_onoffdash);
983 pain_.line(int(x_), y2, int(x_ + label_hfill_), y2,
985 Painter::line_onoffdash);
988 pain_.line(int(x_), y1, int(x_), y0, LColor::added_space);
992 } else if (pit_->isSeparator(pos)) {
993 x_ += singleWidth(pos);
1002 // if we reach the end of a struck out range, paint it
1003 if (running_strikeout) {
1004 int const middle = yo_ + row_.top_of_text()
1005 + ((row_.baseline() - row_.top_of_text()) / 2);
1006 pain_.line(last_strikeout_x, middle, int(x_), middle,
1007 LColor::strikeout, Painter::line_solid, Painter::line_thin);
1008 running_strikeout = false;
1013 void RowPainter::paint()
1015 width_ = text_.workWidth();
1017 separator_ = row_.fill_separator();
1018 hfill_ = row_.fill_hfill();
1019 label_hfill_ = row_.fill_label_hfill();
1021 // FIXME: what is this fixing ?
1022 if (text_.isInInset() && x_ < 0)
1026 // If we're *not* at the top-level of rows, then the
1027 // background has already been cleared.
1028 if (&text_ == bv_.text)
1031 // paint the selection background
1032 if (text_.selection.set())
1035 // vertical lines for appendix
1038 // environment depth brackets
1044 if (row_.pos() == 0)
1047 if (row_.endpos() >= pit_->size())
1055 int paintRows(BufferView const & bv, LyXText const & text,
1056 ParagraphList::iterator pit, RowList::iterator rit,
1057 int xo, int y, int yf, int yo)
1059 //lyxerr << " paintRows: rit: " << &*rit << endl;
1060 int const yy = yf - y;
1061 int const y2 = bv.painter().paperHeight();
1063 ParagraphList::iterator end = text.ownerParagraphs().end();
1064 bool active = false;
1066 for ( ; pit != end; ++pit) {
1067 RowList::iterator row = pit->rows.begin();
1068 RowList::iterator rend = pit->rows.end();
1070 for ( ; row != rend; ++row) {
1074 RowPainter painter(bv, text, pit, row, y + yo, xo, y + bv.top_y());
1080 //lyxerr << " paintRows: row: " << &*row << " ignored" << endl;
1091 int paintText(BufferView & bv)
1093 int const topy = bv.top_y();
1094 ParagraphList::iterator pit;
1095 RowList::iterator rit = bv.text->getRowNearY(topy, pit);
1096 int const y = pit->y + rit->y_offset() - topy;
1097 return paintRows(bv, *bv.text, pit, rit, 0, y, y, 0);
1101 void paintTextInset(BufferView & bv, LyXText & text, int x, int baseline)
1103 RowList::iterator rit = text.firstRow();
1104 RowList::iterator end = text.endRow();
1105 ParagraphList::iterator pit = text.ownerParagraphs().begin();
1107 int y_offset = baseline - rit->ascent_of_text();
1109 while (rit != end && y + rit->height() <= 0) {
1111 text.nextRow(pit, rit);
1114 paintRows(bv, text, pit, rit, x, 0, y, y);
1116 paintRows(bv, text, pit, rit, x, 0, y_offset, y_offset);
1120 int getLengthMarkerHeight(BufferView const & bv, VSpace const & vsp)
1122 if (vsp.kind() == VSpace::NONE)
1125 int const arrow_size = 4;
1126 int const space_size = vsp.inPixels(bv);
1130 int const min_size = max(3 * arrow_size,
1131 font_metrics::maxAscent(font)
1132 + font_metrics::maxDescent(font));
1134 if (vsp.length().len().value() < 0.0)
1137 return max(min_size, space_size);