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 row_;
119 mutable ParagraphList::iterator pit_;
133 RowPainter::RowPainter(BufferView const & bv, LyXText const & text,
134 ParagraphList::iterator pit, RowList::iterator rit,
135 int y_offset, int x_offset, int y)
136 : bv_(bv), pain_(bv_.painter()), text_(text), row_(rit),
137 pit_(pit), xo_(x_offset), yo_(y_offset), y_(y)
142 LyXFont const RowPainter::getFont(pos_type pos) const
144 return text_.getFont(pit_, pos);
148 int RowPainter::singleWidth(lyx::pos_type pos) const
150 return text_.singleWidth(pit_, pos);
154 int RowPainter::singleWidth(lyx::pos_type pos, char c) const
156 LyXFont const & font = text_.getFont(pit_, pos);
157 return text_.singleWidth(pit_, pos, c, font);
161 LyXFont const RowPainter::getLabelFont() const
163 return text_.getLabelFont(pit_);
167 char const RowPainter::transformChar(char c, lyx::pos_type pos) const
169 return text_.transformChar(c, *pit_, pos);
173 int RowPainter::leftMargin() const
175 return text_.leftMargin(pit_, *row_);
179 void RowPainter::paintInset(pos_type const pos)
181 InsetOld * inset = const_cast<InsetOld*>(pit_->getInset(pos));
185 PainterInfo pi(perv(bv_));
186 pi.base.font = getFont(pos);
187 inset->draw(pi, int(x_), yo_ + row_->baseline());
188 x_ += inset->width();
192 void RowPainter::paintHebrewComposeChar(pos_type & vpos)
194 pos_type pos = text_.vis2log(vpos);
199 char c = pit_->getChar(pos);
203 LyXFont const & font = getFont(pos);
204 int const width = font_metrics::width(c, font);
207 for (pos_type i = pos - 1; i >= 0; --i) {
208 c = pit_->getChar(i);
209 if (!Encodings::IsComposeChar_hebrew(c)) {
210 if (IsPrintableNonspace(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_.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)) {
248 dx = (width2 - width) / 2;
254 pain_.text(int(x_) + dx, yo_ + row_->baseline(), str, font);
258 void RowPainter::paintChars(pos_type & vpos, bool hebrew, bool arabic)
260 pos_type pos = text_.vis2log(vpos);
261 pos_type const last = lastPos(*pit_, *row_);
262 LyXFont orig_font = getFont(pos);
266 str += pit_->getChar(pos);
268 unsigned char c = str[0];
269 str[0] = transformChar(c, pos);
272 bool prev_struckout(isDeletedText(*pit_, pos));
273 bool prev_newtext(isInsertedText(*pit_, pos));
277 // collect as much similar chars as we can
278 while (vpos <= last && (pos = text_.vis2log(vpos)) >= 0) {
279 char c = pit_->getChar(pos);
281 if (!IsPrintableNonspace(c))
284 if (prev_struckout != isDeletedText(*pit_, pos))
287 if (prev_newtext != isInsertedText(*pit_, pos))
290 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_.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 RowList::iterator startrow = text_.getRow(text_.selection.start);
394 RowList::iterator endrow = text_.getRow(text_.selection.end);
396 if (text_.bidi_same_direction) {
400 int h = row_->height();
402 if (startrow == row_ && endrow == row_) {
404 x = int(xo_) + startx;
406 pain_.fillRectangle(x, y, w, h, LColor::selection);
410 pain_.fillRectangle(x, y, w, h, LColor::selection);
412 } else if (startrow == row_) {
413 int const x = is_rtl ? int(xo_) : int(xo_ + startx);
414 int const w = is_rtl ? startx : (width_ - startx);
415 pain_.fillRectangle(x, y, w, h, LColor::selection);
416 } else if (endrow == row_) {
417 int const x = is_rtl ? int(xo_ + endx) : int(xo_);
418 int const w = is_rtl ? (width_ - endx) : endx;
419 pain_.fillRectangle(x, y, w, h, LColor::selection);
420 } else if (y_ > starty && y_ < endy) {
421 pain_.fillRectangle(int(xo_), y, width_, h, LColor::selection);
424 } else if (startrow != row_ && endrow != row_) {
425 if (y_ > starty && y_ < endy) {
427 int h = row_->height();
428 pain_.fillRectangle(int(xo_), yo_, w, h, LColor::selection);
433 if ((startrow != row_ && !is_rtl) || (endrow != row_ && is_rtl))
434 pain_.fillRectangle(int(xo_), yo_,
435 int(x_), row_->height(), LColor::selection);
437 pos_type const body_pos = pit_->beginningOfBody();
438 pos_type const last = lastPos(*pit_, *row_);
441 for (pos_type vpos = row_->pos(); vpos <= last; ++vpos) {
442 pos_type pos = text_.vis2log(vpos);
443 double const old_tmpx = tmpx;
444 if (body_pos > 0 && pos == body_pos - 1) {
445 LyXLayout_ptr const & layout = pit_->layout();
446 LyXFont const lfont = getLabelFont();
448 tmpx += label_hfill_ + font_metrics::width(layout->labelsep, lfont);
450 if (pit_->isLineSeparator(body_pos - 1))
451 tmpx -= singleWidth(body_pos - 1);
454 if (hfillExpansion(*pit_, *row_, pos)) {
455 tmpx += singleWidth(pos);
459 tmpx += label_hfill_;
462 else if (pit_->isSeparator(pos)) {
463 tmpx += singleWidth(pos);
467 tmpx += singleWidth(pos);
470 if ((startrow != row_ || text_.selection.start.pos() <= pos) &&
471 (endrow != row_ || pos < text_.selection.end.pos())) {
472 // Here we do not use x_ as xo_ was added to x_.
473 pain_.fillRectangle(int(old_tmpx), yo_,
474 int(tmpx - old_tmpx + 1),
475 row_->height(), LColor::selection);
479 if ((startrow != row_ && is_rtl) || (endrow != row_ && !is_rtl)) {
480 pain_.fillRectangle(int(xo_ + tmpx),
481 yo_, int(bv_.workWidth() - tmpx),
482 row_->height(), LColor::selection);
487 void RowPainter::paintChangeBar()
489 pos_type const start = row_->pos();
490 pos_type const end = lastPos(*pit_, *row_);
492 if (!pit_->isChanged(start, end))
495 int const height = (row_ == text_.lastRow())
497 : row_->height() + boost::next(row_)->top_of_text();
499 pain_.fillRectangle(4, yo_, 5, height, LColor::changebar);
503 void RowPainter::paintAppendix()
505 if (!pit_->params().appendix())
508 // FIXME: can be just width_ ?
509 int const ww = bv_.workWidth();
513 if (pit_->params().startOfAppendix())
514 y += 2 * defaultRowHeight();
516 pain_.line(1, y, 1, yo_ + row_->height(), LColor::appendix);
517 pain_.line(ww - 2, y, ww - 2, yo_ + row_->height(), LColor::appendix);
521 void RowPainter::paintDepthBar()
523 Paragraph::depth_type const depth = pit_->getDepth();
528 Paragraph::depth_type prev_depth = 0;
529 if (row_ != text_.firstRow()) {
530 ParagraphList::iterator pit2 = pit_;
531 if (row_->pos() == 0)
533 prev_depth = pit2->getDepth();
536 Paragraph::depth_type next_depth = 0;
537 if (row_ != text_.lastRow()) {
538 ParagraphList::iterator pit2 = pit_;
539 if (row_->endpos() >= pit2->size())
541 next_depth = pit2->getDepth();
544 for (Paragraph::depth_type i = 1; i <= depth; ++i) {
545 int const w = PAPER_MARGIN / 5;
546 int x = int(w * i + xo_);
547 // only consider the changebar space if we're drawing outer left
549 x += CHANGEBAR_MARGIN;
550 int const h = yo_ + row_->height() - 1 - (i - next_depth - 1) * 3;
552 pain_.line(x, yo_, x, h, LColor::depthbar);
555 pain_.fillRectangle(x, yo_, w, 2, LColor::depthbar);
557 pain_.fillRectangle(x, h, w, 2, LColor::depthbar);
562 int RowPainter::paintLengthMarker(string const & prefix, VSpace const & vsp, int start)
564 if (vsp.kind() == VSpace::NONE)
567 int const arrow_size = 4;
568 int const size = getLengthMarkerHeight(bv_, vsp);
569 int const end = start + size;
571 // the label to display (if any)
573 // y-values for top arrow
575 // y-values for bottom arrow
578 str = prefix + " (" + vsp.asLyXCommand() + ")";
580 if (vsp.kind() == VSpace::VFILL) {
584 // adding or removing space
585 bool const added = vsp.kind() != VSpace::LENGTH ||
586 vsp.length().len().value() > 0.0;
587 ty1 = added ? (start + arrow_size) : start;
588 ty2 = added ? start : (start + arrow_size);
589 by1 = added ? (end - arrow_size) : end;
590 by2 = added ? end : (end - arrow_size);
593 int const leftx = int(xo_) + leftMargin();
594 int const midx = leftx + arrow_size;
595 int const rightx = midx + arrow_size;
603 font.setColor(LColor::added_space);
606 font_metrics::rectText(str, font, w, a, d);
608 pain_.rectText(leftx + 2 * arrow_size + 5,
609 start + ((end - start) / 2) + d,
611 LColor::none, LColor::none);
614 pain_.line(leftx, ty1, midx, ty2, LColor::added_space);
615 pain_.line(midx, ty2, rightx, ty1, LColor::added_space);
618 pain_.line(leftx, by1, midx, by2, LColor::added_space);
619 pain_.line(midx, by2, rightx, by1, LColor::added_space);
622 pain_.line(midx, ty2, midx, by2, LColor::added_space);
628 int RowPainter::paintPageBreak(string const & label, int y)
631 pb_font.setColor(LColor::pagebreak);
637 font_metrics::rectText(label, pb_font, w, a, d);
639 int const text_start = int(xo_ + (width_ - w) / 2);
640 int const text_end = text_start + w;
642 pain_.rectText(text_start, y + d, label, pb_font, LColor::none, LColor::none);
644 pain_.line(int(xo_), y, text_start, y,
645 LColor::pagebreak, Painter::line_onoffdash);
646 pain_.line(text_end, y, int(xo_ + width_), y,
647 LColor::pagebreak, Painter::line_onoffdash);
649 return 3 * defaultRowHeight();
653 int RowPainter::paintAppendixStart(int y)
656 pb_font.setColor(LColor::appendix);
659 string const label = _("Appendix");
663 font_metrics::rectText(label, pb_font, w, a, d);
665 int const text_start = int(xo_ + (width_ - w) / 2);
666 int const text_end = text_start + w;
668 pain_.rectText(text_start, y + d, label, pb_font, LColor::none, LColor::none);
670 pain_.line(int(xo_ + 1), y, text_start, y, LColor::appendix);
671 pain_.line(text_end, y, int(xo_ + width_ - 2), y, LColor::appendix);
673 return 3 * defaultRowHeight();
677 void RowPainter::paintFirst()
679 ParagraphParameters const & parparams = pit_->params();
683 // start of appendix?
684 if (parparams.startOfAppendix())
685 y_top += paintAppendixStart(yo_ + y_top + 2 * defaultRowHeight());
688 if (row_ == text_.firstRow() && !text_.isInInset())
689 y_top += PAPER_MARGIN;
691 // draw a top pagebreak
692 if (parparams.pagebreakTop())
693 y_top += paintPageBreak(_("Page Break (top)"),
694 yo_ + y_top + 2 * defaultRowHeight());
696 // draw the additional space if needed:
697 y_top += paintLengthMarker(_("Space above"), parparams.spaceTop(),
700 Buffer const & buffer = *bv_.buffer();
702 LyXLayout_ptr const & layout = pit_->layout();
704 if (buffer.params().paragraph_separation == BufferParams::PARSEP_SKIP) {
705 if (pit_ != text_.ownerParagraphs().begin()) {
706 if (layout->latextype == LATEX_PARAGRAPH
707 && !pit_->getDepth()) {
708 y_top += buffer.params().getDefSkip().inPixels(bv_);
710 LyXLayout_ptr const & playout =
711 boost::prior(pit_)->layout();
712 if (playout->latextype == LATEX_PARAGRAPH
713 && !boost::prior(pit_)->getDepth()) {
714 // is it right to use defskip here, too? (AS)
715 y_top += buffer.params().getDefSkip().inPixels(bv_);
721 int const ww = bv_.workWidth();
724 if (parparams.lineTop()) {
725 int const asc = font_metrics::ascent('x', getFont(0));
729 int const w = (text_.isInInset() ? text_.inset_owner->width() : ww);
730 int const xp = static_cast<int>(text_.isInInset() ? xo_ : 0);
731 pain_.line(xp, yo_ + y_top, xp + w, yo_ + y_top,
732 LColor::topline, Painter::line_solid,
733 Painter::line_thick);
738 bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params());
739 bool const is_seq = isFirstInSequence(pit_, text_.ownerParagraphs());
740 //lyxerr << "paintFirst: " << pit_->id() << " is_seq: " << is_seq << std::endl;
742 // should we print a label?
743 if (layout->labeltype >= LABEL_STATIC
744 && (layout->labeltype != LABEL_STATIC
745 || layout->latextype != LATEX_ENVIRONMENT
748 LyXFont font = getLabelFont();
749 if (!pit_->getLabelstring().empty()) {
751 string const str = pit_->getLabelstring();
753 // this is special code for the chapter layout. This is
754 // printed in an extra row and has a pagebreak at
756 if (layout->counter == "chapter") {
757 if (buffer.params().secnumdepth >= 0) {
758 float spacing_val = 1.0;
759 if (!parparams.spacing().isDefault()) {
760 spacing_val = parparams.spacing().getValue();
762 spacing_val = buffer.params().spacing().getValue();
766 int(font_metrics::maxDescent(font) * layout->spacing.getValue() * spacing_val)
767 + int(layout->parsep) * defaultRowHeight();
770 x = ww - leftMargin() -
771 font_metrics::width(str, font);
775 yo_ + row_->baseline() -
776 row_->ascent_of_text() - maxdesc,
781 x = ww - leftMargin()
782 + font_metrics::width(layout->labelsep, font);
784 x = x_ - font_metrics::width(layout->labelsep, font)
785 - font_metrics::width(str, font);
788 pain_.text(int(x), yo_ + row_->baseline(), str, font);
792 // the labels at the top of an environment.
793 // More or less for bibliography
795 (layout->labeltype == LABEL_TOP_ENVIRONMENT ||
796 layout->labeltype == LABEL_BIBLIO ||
797 layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)) {
798 LyXFont font = getLabelFont();
799 if (!pit_->getLabelstring().empty()) {
800 string const str = pit_->getLabelstring();
801 float spacing_val = 1.0;
802 if (!parparams.spacing().isDefault()) {
803 spacing_val = parparams.spacing().getValue();
805 spacing_val = buffer.params().spacing().getValue();
809 int(font_metrics::maxDescent(font) * layout->spacing.getValue() * spacing_val
810 + (layout->labelbottomsep * defaultRowHeight()));
813 if (layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
814 x = ((is_rtl ? leftMargin() : x_)
815 + ww - text_.rightMargin(*pit_, *bv_.buffer(), *row_)) / 2;
816 x -= font_metrics::width(str, font) / 2;
818 x = ww - leftMargin() -
819 font_metrics::width(str, font);
822 yo_ + row_->baseline() - row_->ascent_of_text() - maxdesc,
829 void RowPainter::paintLast()
831 ParagraphParameters const & parparams = pit_->params();
832 int y_bottom = row_->height() - 1;
835 if (row_ == text_.lastRow() && !text_.isInInset())
836 y_bottom -= PAPER_MARGIN;
838 int const ww = bv_.workWidth();
840 // draw a bottom pagebreak
841 if (parparams.pagebreakBottom()) {
842 y_bottom -= paintPageBreak(_("Page Break (bottom)"),
843 yo_ + y_bottom - 2 * defaultRowHeight());
846 // draw the additional space if needed:
847 int const height = getLengthMarkerHeight(bv_, parparams.spaceBottom());
848 y_bottom -= paintLengthMarker(_("Space below"), parparams.spaceBottom(),
849 yo_ + y_bottom - height);
851 // draw a bottom line
852 if (parparams.lineBottom()) {
853 int const asc = font_metrics::ascent('x',
854 getFont(max(pos_type(0), pit_->size() - 1)));
858 int const w = text_.isInInset() ? text_.inset_owner->width() : ww;
859 int const xp = int(text_.isInInset() ? xo_ : 0);
860 int const y = yo_ + y_bottom;
861 pain_.line(xp, y, xp + w, y, LColor::topline, Painter::line_solid,
862 Painter::line_thick);
867 bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params());
868 int const endlabel = getEndLabel(pit_, text_.ownerParagraphs());
873 case END_LABEL_FILLED_BOX:
875 LyXFont const font = getLabelFont();
876 int const size = int(0.75 * font_metrics::maxAscent(font));
877 int const y = (yo_ + row_->baseline()) - size;
878 int x = is_rtl ? LEFT_MARGIN : ww - PAPER_MARGIN - size;
880 if (row_->fill() <= size)
881 x += (size - row_->fill() + 1) * (is_rtl ? -1 : 1);
883 if (endlabel == END_LABEL_BOX)
884 pain_.rectangle(x, y, size, size, LColor::eolmarker);
886 pain_.fillRectangle(x, y, size, size, LColor::eolmarker);
889 case END_LABEL_STATIC:
891 LyXFont font = getLabelFont();
892 string const & str = pit_->layout()->endlabelstring();
893 double const x = is_rtl ?
894 x_ - font_metrics::width(str, font)
895 : ww - text_.rightMargin(*pit_, *bv_.buffer(), *row_) - row_->fill();
896 pain_.text(int(x), yo_ + row_->baseline(), str, font);
899 case END_LABEL_NO_LABEL:
905 void RowPainter::paintText()
907 pos_type const last = lastPos(*pit_, *row_);
908 pos_type body_pos = pit_->beginningOfBody();
910 (body_pos - 1 > last || !pit_->isLineSeparator(body_pos - 1))) {
914 LyXLayout_ptr const & layout = pit_->layout();
916 bool running_strikeout = false;
917 bool is_struckout = false;
918 int last_strikeout_x = 0;
920 pos_type vpos = row_->pos();
921 while (vpos <= last) {
922 if (x_ > bv_.workWidth())
924 pos_type pos = text_.vis2log(vpos);
926 if (pos >= pit_->size()) {
931 if (x_ + singleWidth(pos) < 0) {
932 x_ += singleWidth(pos);
937 is_struckout = isDeletedText(*pit_, pos);
939 if (is_struckout && !running_strikeout) {
940 running_strikeout = true;
941 last_strikeout_x = int(x_);
944 bool const highly_editable_inset = pit_->isInset(pos)
945 && isHighlyEditableInset(pit_->getInset(pos));
947 // if we reach the end of a struck out range, paint it
948 // we also don't paint across things like tables
949 if (running_strikeout && (highly_editable_inset || !is_struckout)) {
950 int const middle = yo_ + row_->top_of_text()
951 + (row_->baseline() - row_->top_of_text()) / 2;
952 pain_.line(last_strikeout_x, middle, int(x_), middle,
953 LColor::strikeout, Painter::line_solid, Painter::line_thin);
954 running_strikeout = false;
957 if (body_pos > 0 && pos == body_pos - 1) {
958 int const lwidth = font_metrics::width(layout->labelsep,
961 x_ += label_hfill_ + lwidth - singleWidth(body_pos - 1);
964 if (pit_->isHfill(pos)) {
967 int const y0 = yo_ + row_->baseline();
968 int const y1 = y0 - defaultRowHeight() / 2;
970 pain_.line(int(x_), y1, int(x_), y0, LColor::added_space);
972 if (hfillExpansion(*pit_, *row_, pos)) {
973 int const y2 = (y0 + y1) / 2;
975 if (pos >= body_pos) {
976 pain_.line(int(x_), y2, int(x_ + hfill_), y2,
978 Painter::line_onoffdash);
981 pain_.line(int(x_), y2, int(x_ + label_hfill_), y2,
983 Painter::line_onoffdash);
986 pain_.line(int(x_), y1, int(x_), y0, LColor::added_space);
990 } else if (pit_->isSeparator(pos)) {
991 x_ += singleWidth(pos);
1000 // if we reach the end of a struck out range, paint it
1001 if (running_strikeout) {
1002 int const middle = yo_ + row_->top_of_text()
1003 + ((row_->baseline() - row_->top_of_text()) / 2);
1004 pain_.line(last_strikeout_x, middle, int(x_), middle,
1005 LColor::strikeout, Painter::line_solid, Painter::line_thin);
1006 running_strikeout = false;
1011 void RowPainter::paint()
1013 width_ = text_.workWidth();
1015 separator_ = row_->fill_separator();
1016 hfill_ = row_->fill_hfill();
1017 label_hfill_ = row_->fill_label_hfill();
1019 // FIXME: what is this fixing ?
1020 if (text_.isInInset() && x_ < 0)
1024 // If we're *not* at the top-level of rows, then the
1025 // background has already been cleared.
1026 if (&text_ == bv_.text)
1029 // paint the selection background
1030 if (text_.selection.set())
1033 // vertical lines for appendix
1036 // environment depth brackets
1042 if (row_->pos() == 0)
1045 if (row_->endpos() >= pit_->size())
1053 int paintRows(BufferView const & bv, LyXText const & text,
1054 ParagraphList::iterator pit, RowList::iterator rit,
1055 int xo, int y, int yf, int yo)
1057 //lyxerr << " paintRows: rit: " << &*rit << endl;
1058 //const_cast<LyXText&>(text).updateRowPositions();
1059 int const yy = yf - y;
1060 int const y2 = bv.painter().paperHeight();
1062 ParagraphList::iterator end = text.ownerParagraphs().end();
1063 bool active = false;
1065 for ( ; pit != end; ++pit) {
1066 RowList::iterator row = pit->rows.begin();
1067 RowList::iterator rend = pit->rows.end();
1069 for ( ; row != rend; ++row) {
1073 RowPainter painter(bv, text, pit, row, y + yo, xo, y + bv.top_y());
1079 //lyxerr << " paintRows: row: " << &*row << " ignored" << endl;
1090 int paintText(BufferView & bv)
1092 int const topy = bv.top_y();
1093 ParagraphList::iterator pit;
1094 RowList::iterator rit = bv.text->getRowNearY(topy, pit);
1095 int const y = pit->y + rit->y_offset() - topy;
1096 return paintRows(bv, *bv.text, pit, rit, 0, y, y, 0);
1100 void paintTextInset(BufferView & bv, LyXText & text, int x, int baseline)
1102 RowList::iterator rit = text.firstRow();
1103 RowList::iterator end = text.endRow();
1104 ParagraphList::iterator pit = text.ownerParagraphs().begin();
1106 int y_offset = baseline - rit->ascent_of_text();
1108 while (rit != end && y + rit->height() <= 0) {
1110 text.nextRow(pit, rit);
1113 paintRows(bv, text, pit, rit, x, 0, y, y);
1115 paintRows(bv, text, pit, rit, x, 0, y_offset, y_offset);
1119 int getLengthMarkerHeight(BufferView const & bv, VSpace const & vsp)
1121 if (vsp.kind() == VSpace::NONE)
1124 int const arrow_size = 4;
1125 int const space_size = vsp.inPixels(bv);
1129 int const min_size = max(3 * arrow_size,
1130 font_metrics::maxAscent(font)
1131 + font_metrics::maxDescent(font));
1133 if (vsp.length().len().value() < 0.0)
1136 return max(min_size, space_size);