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 "frontends/Painter.h"
15 #include "frontends/screen.h"
16 #include "frontends/font_metrics.h"
17 #include "support/LAssert.h"
18 #include "paragraph.h"
19 #include "paragraph_funcs.h"
20 #include "support/textutils.h"
22 #include "insets/insettext.h"
23 #include "ParagraphParameters.h"
24 #include "BufferView.h"
31 #include "rowpainter.h"
33 #include "lyxrow_funcs.h"
34 #include "metricsinfo.h"
38 using namespace lyx::support;
43 extern int PAPER_MARGIN;
44 extern int CHANGEBAR_MARGIN;
45 extern int LEFT_MARGIN;
49 // "temporary". We'll never get to use more
50 // references until we start adding hacks like
51 // these until other places catch up.
52 BufferView * perv(BufferView const & bv)
54 return const_cast<BufferView *>(&bv);
58 * A class used for painting an individual row of text.
62 /// initialise painter
63 RowPainter(BufferView const & bv, LyXText const & text,
64 RowList::iterator rit, int y_offset, int x_offset, int y);
69 // paint various parts
70 void paintBackground();
71 void paintSelection();
74 void paintChangeBar();
77 void paintForeignMark(float const orig_x, LyXFont const & orig_font);
78 void paintHebrewComposeChar(lyx::pos_type & vpos);
79 void paintArabicComposeChar(lyx::pos_type & vpos);
80 void paintChars(lyx::pos_type & vpos, bool hebrew, bool arabic);
81 int paintPageBreak(string const & label, int y);
82 int paintAppendixStart(int y);
83 int paintLengthMarker(string const & prefix, VSpace const & vsp, int start);
85 void paintFromPos(lyx::pos_type & vpos);
86 void paintInset(lyx::pos_type const pos);
88 /// return left margin
89 int leftMargin() const;
91 /// return the font at the given pos
92 LyXFont const getFont(lyx::pos_type pos) const;
94 /// return the label font for this row
95 LyXFont const getLabelFont() const;
97 char const transformChar(char c, lyx::pos_type pos) const;
99 /// return pixel width for the given pos
100 int singleWidth(lyx::pos_type pos) const;
101 int singleWidth(lyx::pos_type pos, char c) const;
103 /// bufferview to paint on
104 BufferView const & bv_;
109 /// LyXText for the row
110 LyXText const & text_;
113 RowList::iterator row_;
116 mutable ParagraphList::iterator pit_;
129 RowPainter::RowPainter(BufferView const & bv, LyXText const & text,
130 RowList::iterator rit,
131 int y_offset, int x_offset, int y)
132 : bv_(bv), pain_(bv_.painter()), text_(text), row_(rit),
134 xo_(x_offset), yo_(y_offset), y_(y)
139 LyXFont const RowPainter::getFont(pos_type pos) const
141 return text_.getFont(bv_.buffer(), pit_, pos);
145 int RowPainter::singleWidth(lyx::pos_type pos) const
147 return text_.singleWidth(pit_, pos);
151 int RowPainter::singleWidth(lyx::pos_type pos, char c) const
153 return text_.singleWidth(pit_, pos, c);
157 LyXFont const RowPainter::getLabelFont() const
159 return text_.getLabelFont(bv_.buffer(), pit_);
163 char const RowPainter::transformChar(char c, lyx::pos_type pos) const
165 return text_.transformChar(c, *pit_, pos);
169 int RowPainter::leftMargin() const
171 return text_.leftMargin(*row_);
175 void RowPainter::paintInset(pos_type const pos)
177 Inset * inset = const_cast<Inset*>(pit_->getInset(pos));
181 PainterInfo pi(perv(bv_));
182 pi.base.font = getFont(pos);
183 int const w = inset->width(perv(bv_), pi.base.font);
184 inset->draw(pi, int(x_), yo_ + row_->baseline());
189 void RowPainter::paintHebrewComposeChar(pos_type & vpos)
191 pos_type pos = text_.vis2log(vpos);
196 char c = pit_->getChar(pos);
200 LyXFont const & font = getFont(pos);
201 int const width = font_metrics::width(c, font);
204 for (pos_type i = pos - 1; i >= 0; --i) {
205 c = pit_->getChar(i);
206 if (!Encodings::IsComposeChar_hebrew(c)) {
207 if (IsPrintableNonspace(c)) {
211 dx = (c == 'ø' || c == 'ã')
213 : (width2 - width) / 2;
220 pain_.text(int(x_) + dx, yo_ + row_->baseline(), str, font);
224 void RowPainter::paintArabicComposeChar(pos_type & vpos)
226 pos_type pos = text_.vis2log(vpos);
230 char c = pit_->getChar(pos);
231 c = transformChar(c, pos);
235 LyXFont const & font = getFont(pos);
236 int const width = font_metrics::width(c, font);
239 for (pos_type i = pos - 1; i >= 0; --i) {
240 c = pit_->getChar(i);
241 if (!Encodings::IsComposeChar_arabic(c)) {
242 if (IsPrintableNonspace(c)) {
245 dx = (width2 - width) / 2;
251 pain_.text(int(x_) + dx, yo_ + row_->baseline(), str, font);
255 void RowPainter::paintChars(pos_type & vpos, bool hebrew, bool arabic)
257 pos_type pos = text_.vis2log(vpos);
258 pos_type const last = lastPrintablePos(text_, row_);
259 LyXFont orig_font = getFont(pos);
263 str += pit_->getChar(pos);
265 unsigned char c = str[0];
266 str[0] = transformChar(c, pos);
269 bool prev_struckout(isDeletedText(*pit_, pos));
270 bool prev_newtext(isInsertedText(*pit_, pos));
274 // collect as much similar chars as we can
275 while (vpos <= last && (pos = text_.vis2log(vpos)) >= 0) {
276 char c = pit_->getChar(pos);
278 if (!IsPrintableNonspace(c))
281 if (prev_struckout != isDeletedText(*pit_, pos))
284 if (prev_newtext != isInsertedText(*pit_, pos))
287 if (arabic && Encodings::IsComposeChar_arabic(c))
289 if (hebrew && Encodings::IsComposeChar_hebrew(c))
292 if (orig_font != getFont(pos))
296 c = transformChar(c, pos);
301 if (prev_struckout) {
302 orig_font.setColor(LColor::strikeout);
303 } else if (prev_newtext) {
304 orig_font.setColor(LColor::newtext);
307 // Draw text and set the new x position
308 pain_.text(int(x_), yo_ + row_->baseline(), str, orig_font);
309 x_ += font_metrics::width(str, orig_font);
313 void RowPainter::paintForeignMark(float const orig_x, LyXFont const & orig_font)
315 if (!lyxrc.mark_foreign_language)
317 if (orig_font.language() == latex_language)
319 if (orig_font.language() == bv_.buffer()->params.language)
322 int const y = yo_ + row_->baseline() + 1;
323 pain_.line(int(orig_x), y, int(x_), y, LColor::language);
327 void RowPainter::paintFromPos(pos_type & vpos)
329 pos_type const pos = text_.vis2log(vpos);
331 LyXFont const & orig_font = getFont(pos);
333 float const orig_x = x_;
335 char const c = pit_->getChar(pos);
337 if (IsInsetChar(c)) {
340 paintForeignMark(orig_x, orig_font);
344 // usual characters, no insets
346 // special case languages
347 bool const hebrew = (orig_font.language()->lang() == "hebrew");
349 orig_font.language()->lang() == "arabic" &&
350 (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
351 lyxrc.font_norm_type == LyXRC::ISO_10646_1);
353 // draw as many chars as we can
354 if ((!hebrew && !arabic)
355 || (hebrew && !Encodings::IsComposeChar_hebrew(c))
356 || (arabic && !Encodings::IsComposeChar_arabic(c))) {
357 paintChars(vpos, hebrew, arabic);
359 paintHebrewComposeChar(vpos);
361 paintArabicComposeChar(vpos);
364 paintForeignMark(orig_x, orig_font);
370 void RowPainter::paintBackground()
373 int const y = yo_ < 0 ? 0 : yo_;
374 int const h = yo_ < 0 ? row_->height() + yo_ : row_->height();
375 pain_.fillRectangle(x, y, width_, h, text_.backgroundColor());
379 void RowPainter::paintSelection()
381 bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params);
383 // the current selection
384 int const startx = text_.selection.start.x();
385 int const endx = text_.selection.end.x();
386 int const starty = text_.selection.start.y();
387 int const endy = text_.selection.end.y();
388 RowList::iterator startrow = text_.getRow(text_.selection.start);
389 RowList::iterator endrow = text_.getRow(text_.selection.end);
391 if (text_.bidi_same_direction) {
395 int h = row_->height();
397 if (startrow == row_ && endrow == row_) {
401 pain_.fillRectangle(x, y, w, h, LColor::selection);
405 pain_.fillRectangle(x, y, w, h, LColor::selection);
407 } else if (startrow == row_) {
408 int const x = (is_rtl) ? xo_ : (xo_ + startx);
409 int const w = (is_rtl) ? startx : (width_ - startx);
410 pain_.fillRectangle(x, y, w, h, LColor::selection);
411 } else if (endrow == row_) {
412 int const x = (is_rtl) ? (xo_ + endx) : xo_;
413 int const w = (is_rtl) ? (width_ - endx) : endx;
414 pain_.fillRectangle(x, y, w, h, LColor::selection);
415 } else if (y_ > starty && y_ < endy) {
416 pain_.fillRectangle(xo_, y, width_, h, LColor::selection);
419 } else if (startrow != row_ && endrow != row_) {
420 if (y_ > starty && y_ < endy) {
422 int h = row_->height();
423 pain_.fillRectangle(xo_, yo_, w, h, LColor::selection);
428 if ((startrow != row_ && !is_rtl) || (endrow != row_ && is_rtl))
429 pain_.fillRectangle(xo_, yo_, int(x_), row_->height(), LColor::selection);
431 pos_type const body_pos = pit_->beginningOfBody();
432 pos_type const last = lastPrintablePos(text_, row_);
435 for (pos_type vpos = row_->pos(); vpos <= last; ++vpos) {
436 pos_type pos = text_.vis2log(vpos);
437 float const old_tmpx = tmpx;
438 if (body_pos > 0 && pos == body_pos - 1) {
439 LyXLayout_ptr const & layout = pit_->layout();
440 LyXFont const lfont = getLabelFont();
442 tmpx += label_hfill_ + font_metrics::width(layout->labelsep, lfont);
444 if (pit_->isLineSeparator(body_pos - 1))
445 tmpx -= singleWidth(body_pos - 1);
448 if (hfillExpansion(text_, row_, pos)) {
449 tmpx += singleWidth(pos);
453 tmpx += label_hfill_;
456 else if (pit_->isSeparator(pos)) {
457 tmpx += singleWidth(pos);
461 tmpx += singleWidth(pos);
464 if ((startrow != row_ || text_.selection.start.pos() <= pos) &&
465 (endrow != row_ || pos < text_.selection.end.pos())) {
466 // Here we do not use x_ as xo_ was added to x_.
467 pain_.fillRectangle(int(old_tmpx), yo_,
468 int(tmpx - old_tmpx + 1),
469 row_->height(), LColor::selection);
473 if ((startrow != row_ && is_rtl) || (endrow != row_ && !is_rtl)) {
474 pain_.fillRectangle(xo_ + int(tmpx),
475 yo_, int(bv_.workWidth() - tmpx),
476 row_->height(), LColor::selection);
481 void RowPainter::paintChangeBar()
483 pos_type const start = row_->pos();
484 pos_type const end = lastPrintablePos(text_, row_);
486 if (!pit_->isChanged(start, end))
489 int const height = (boost::next(row_) != text_.rows().end()
490 ? row_->height() + boost::next(row_)->top_of_text()
493 pain_.fillRectangle(4, yo_, 5, height, LColor::changebar);
497 void RowPainter::paintAppendix()
499 if (!pit_->params().appendix())
502 // FIXME: can be just width_ ?
503 int const ww = bv_.workWidth();
507 if (pit_->params().startOfAppendix())
508 y += 2 * defaultRowHeight();
510 pain_.line(1, y, 1, yo_ + row_->height(), LColor::appendix);
511 pain_.line(ww - 2, y, ww - 2, yo_ + row_->height(), LColor::appendix);
515 void RowPainter::paintDepthBar()
517 Paragraph::depth_type const depth = pit_->getDepth();
522 Paragraph::depth_type prev_depth = 0;
523 if (row_ != text_.rows().begin())
524 prev_depth = boost::prior(row_)->par()->getDepth();
525 Paragraph::depth_type next_depth = 0;
527 RowList::iterator next_row = boost::next(row_);
528 if (next_row != text_.rows().end())
529 next_depth = next_row->par()->getDepth();
531 for (Paragraph::depth_type i = 1; i <= depth; ++i) {
532 int x = (PAPER_MARGIN / 5) * i + xo_;
533 // only consider the changebar space if we're drawing outer left
535 x += CHANGEBAR_MARGIN;
536 int const h = yo_ + row_->height() - 1 - (i - next_depth - 1) * 3;
538 pain_.line(x, yo_, x, h, LColor::depthbar);
540 int const w = PAPER_MARGIN / 5;
542 if (i > prev_depth) {
543 pain_.fillRectangle(x, yo_, w, 2, LColor::depthbar);
545 if (i > next_depth) {
546 pain_.fillRectangle(x, h, w, 2, LColor::depthbar);
552 int RowPainter::paintLengthMarker(string const & prefix, VSpace const & vsp, int start)
554 if (vsp.kind() == VSpace::NONE)
557 int const arrow_size = 4;
558 int const size = getLengthMarkerHeight(bv_, vsp);
559 int const end = start + size;
561 // the label to display (if any)
563 // y-values for top arrow
565 // y-values for bottom arrow
568 str = prefix + " (" + vsp.asLyXCommand() + ")";
570 if (vsp.kind() == VSpace::VFILL) {
574 // adding or removing space
575 bool const added = vsp.kind() != VSpace::LENGTH ||
576 vsp.length().len().value() > 0.0;
577 ty1 = added ? (start + arrow_size) : start;
578 ty2 = added ? start : (start + arrow_size);
579 by1 = added ? (end - arrow_size) : end;
580 by2 = added ? end : (end - arrow_size);
583 int const leftx = xo_ + leftMargin();
584 int const midx = leftx + arrow_size;
585 int const rightx = midx + arrow_size;
593 font.setColor(LColor::added_space).decSize().decSize();
594 font_metrics::rectText(str, font, w, a, d);
596 pain_.rectText(leftx + 2 * arrow_size + 5,
597 start + ((end - start) / 2) + d,
601 pain_.line(leftx, ty1, midx, ty2, LColor::added_space);
602 pain_.line(midx, ty2, rightx, ty1, LColor::added_space);
605 pain_.line(leftx, by1, midx, by2, LColor::added_space);
606 pain_.line(midx, by2, rightx, by1, LColor::added_space);
609 pain_.line(midx, ty2, midx, by2, LColor::added_space);
615 int RowPainter::paintPageBreak(string const & label, int y)
618 pb_font.setColor(LColor::pagebreak).decSize();
623 font_metrics::rectText(label, pb_font, w, a, d);
625 int const text_start = xo_ + ((width_ - w) / 2);
626 int const text_end = text_start + w;
628 pain_.rectText(text_start, y + d, label, pb_font);
630 pain_.line(xo_, y, text_start, y,
631 LColor::pagebreak, Painter::line_onoffdash);
632 pain_.line(text_end, y, xo_ + width_, y,
633 LColor::pagebreak, Painter::line_onoffdash);
635 return 3 * defaultRowHeight();
639 int RowPainter::paintAppendixStart(int y)
642 pb_font.setColor(LColor::appendix).decSize();
644 string const label = _("Appendix");
648 font_metrics::rectText(label, pb_font, w, a, d);
650 int const text_start = xo_ + ((width_ - w) / 2);
651 int const text_end = text_start + w;
653 pain_.rectText(text_start, y + d, label, pb_font);
655 pain_.line(xo_ + 1, y, text_start, y, LColor::appendix);
656 pain_.line(text_end, y, xo_ + width_ - 2, y, LColor::appendix);
658 return 3 * defaultRowHeight();
662 void RowPainter::paintFirst()
664 ParagraphParameters const & parparams = pit_->params();
668 // start of appendix?
669 if (parparams.startOfAppendix()) {
670 y_top += paintAppendixStart(yo_ + y_top + 2 * defaultRowHeight());
674 if (row_ == text_.rows().begin() && !text_.isInInset())
675 y_top += PAPER_MARGIN;
677 // draw a top pagebreak
678 if (parparams.pagebreakTop()) {
679 y_top += paintPageBreak(_("Page Break (top)"),
680 yo_ + y_top + 2 * defaultRowHeight());
683 // draw the additional space if needed:
684 y_top += paintLengthMarker(_("Space above"), parparams.spaceTop(),
687 Buffer const * buffer = bv_.buffer();
689 LyXLayout_ptr const & layout = pit_->layout();
691 if (buffer->params.paragraph_separation == BufferParams::PARSEP_SKIP) {
692 if (pit_ != text_.ownerParagraphs().begin()) {
693 if (layout->latextype == LATEX_PARAGRAPH
694 && !pit_->getDepth()) {
695 y_top += buffer->params.getDefSkip().inPixels(bv_);
697 LyXLayout_ptr const & playout =
698 boost::prior(pit_)->layout();
699 if (playout->latextype == LATEX_PARAGRAPH
700 && !boost::prior(pit_)->getDepth()) {
701 // is it right to use defskip here, too? (AS)
702 y_top += buffer->params.getDefSkip().inPixels(bv_);
708 int const ww = bv_.workWidth();
711 if (parparams.lineTop()) {
712 LyXFont font(LyXFont::ALL_SANE);
713 int const asc = font_metrics::ascent('x', getFont(0));
717 int const w = (text_.isInInset() ? text_.inset_owner->width(perv(bv_), font) : ww);
718 int const xp = static_cast<int>(text_.isInInset() ? xo_ : 0);
719 pain_.line(xp, yo_ + y_top, xp + w, yo_ + y_top,
720 LColor::topline, Painter::line_solid,
721 Painter::line_thick);
726 bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params);
728 // should we print a label?
729 if (layout->labeltype >= LABEL_STATIC
730 && (layout->labeltype != LABEL_STATIC
731 || layout->latextype != LATEX_ENVIRONMENT
732 || isFirstInSequence(pit_, text_.ownerParagraphs()))) {
734 LyXFont font = getLabelFont();
735 if (!pit_->getLabelstring().empty()) {
737 string const str = pit_->getLabelstring();
739 // this is special code for the chapter layout. This is
740 // printed in an extra row and has a pagebreak at
742 if (layout->labeltype == LABEL_COUNTER_CHAPTER) {
743 if (buffer->params.secnumdepth >= 0) {
744 float spacing_val = 1.0;
745 if (!parparams.spacing().isDefault()) {
746 spacing_val = parparams.spacing().getValue();
748 spacing_val = buffer->params.spacing.getValue();
752 int(font_metrics::maxDescent(font) * layout->spacing.getValue() * spacing_val)
753 + int(layout->parsep) * defaultRowHeight();
756 x = ww - leftMargin() -
757 font_metrics::width(str, font);
761 yo_ + row_->baseline() -
762 row_->ascent_of_text() - maxdesc,
767 x = ww - leftMargin()
768 + font_metrics::width(layout->labelsep, font);
770 x = x_ - font_metrics::width(layout->labelsep, font)
771 - font_metrics::width(str, font);
774 pain_.text(int(x), yo_ + row_->baseline(), str, font);
778 // the labels at the top of an environment.
779 // More or less for bibliography
780 } else if (isFirstInSequence(pit_, text_.ownerParagraphs()) &&
781 (layout->labeltype == LABEL_TOP_ENVIRONMENT ||
782 layout->labeltype == LABEL_BIBLIO ||
783 layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)) {
784 LyXFont font = getLabelFont();
785 if (!pit_->getLabelstring().empty()) {
786 string const str = pit_->getLabelstring();
787 float spacing_val = 1.0;
788 if (!parparams.spacing().isDefault()) {
789 spacing_val = parparams.spacing().getValue();
791 spacing_val = buffer->params.spacing.getValue();
795 int(font_metrics::maxDescent(font) * layout->spacing.getValue() * spacing_val
796 + (layout->labelbottomsep * defaultRowHeight()));
799 if (layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
800 x = ((is_rtl ? leftMargin() : x_)
801 + ww - text_.rightMargin(*bv_.buffer(), *row_)) / 2;
802 x -= font_metrics::width(str, font) / 2;
804 x = ww - leftMargin() -
805 font_metrics::width(str, font);
807 pain_.text(int(x), yo_ + row_->baseline()
808 - row_->ascent_of_text() - maxdesc,
815 void RowPainter::paintLast()
817 ParagraphParameters const & parparams = pit_->params();
818 int y_bottom = row_->height() - 1;
821 if (boost::next(row_) == text_.rows().end() && !text_.isInInset())
822 y_bottom -= PAPER_MARGIN;
824 int const ww = bv_.workWidth();
826 // draw a bottom pagebreak
827 if (parparams.pagebreakBottom()) {
828 y_bottom -= paintPageBreak(_("Page Break (bottom)"),
829 yo_ + y_bottom - 2 * defaultRowHeight());
832 // draw the additional space if needed:
833 int const height = getLengthMarkerHeight(bv_, parparams.spaceBottom());
834 y_bottom -= paintLengthMarker(_("Space below"), parparams.spaceBottom(),
835 yo_ + y_bottom - height);
837 // draw a bottom line
838 if (parparams.lineBottom()) {
839 LyXFont font(LyXFont::ALL_SANE);
840 int const asc = font_metrics::ascent('x',
841 getFont(max(pos_type(0), pit_->size() - 1)));
845 int const w = (text_.isInInset() ? text_.inset_owner->width(perv(bv_), font) : ww);
846 int const xp = static_cast<int>(text_.isInInset() ? xo_ : 0);
847 int const y = yo_ + y_bottom;
848 pain_.line(xp, y, xp + w, y, LColor::topline, Painter::line_solid,
849 Painter::line_thick);
854 bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params);
855 int const endlabel = getEndLabel(pit_, text_.ownerParagraphs());
860 case END_LABEL_FILLED_BOX:
862 LyXFont const font = getLabelFont();
863 int const size = int(0.75 * font_metrics::maxAscent(font));
864 int const y = (yo_ + row_->baseline()) - size;
865 int x = is_rtl ? LEFT_MARGIN : ww - PAPER_MARGIN - size;
867 if (row_->fill() <= size)
868 x += (size - row_->fill() + 1) * (is_rtl ? -1 : 1);
870 if (endlabel == END_LABEL_BOX) {
871 pain_.rectangle(x, y, size, size, LColor::eolmarker);
873 pain_.fillRectangle(x, y, size, size, LColor::eolmarker);
877 case END_LABEL_STATIC:
879 LyXFont font = getLabelFont();
880 string const & str = pit_->layout()->endlabelstring();
881 int const x = is_rtl ?
882 int(x_) - font_metrics::width(str, font)
883 : ww - text_.rightMargin(*bv_.buffer(), *row_) - row_->fill();
884 pain_.text(x, yo_ + row_->baseline(), str, font);
887 case END_LABEL_NO_LABEL:
893 void RowPainter::paintText()
895 pos_type const last = lastPrintablePos(text_, row_);
896 pos_type body_pos = pit_->beginningOfBody();
898 (body_pos - 1 > last ||
899 !pit_->isLineSeparator(body_pos - 1))) {
903 LyXLayout_ptr const & layout = pit_->layout();
905 bool running_strikeout = false;
906 bool is_struckout = false;
907 float last_strikeout_x = 0.0;
909 pos_type vpos = row_->pos();
910 while (vpos <= last) {
911 if (x_ > bv_.workWidth())
913 pos_type pos = text_.vis2log(vpos);
915 if (pos >= pit_->size()) {
920 if (x_ + singleWidth(pos) < 0) {
921 x_ += singleWidth(pos);
926 is_struckout = isDeletedText(*pit_, pos);
928 if (is_struckout && !running_strikeout) {
929 running_strikeout = true;
930 last_strikeout_x = x_;
933 bool const highly_editable_inset = pit_->isInset(pos)
934 && isHighlyEditableInset(pit_->getInset(pos));
936 // if we reach the end of a struck out range, paint it
937 // we also don't paint across things like tables
938 if (running_strikeout && (highly_editable_inset || !is_struckout)) {
939 int const middle = yo_ + row_->top_of_text()
940 + ((row_->baseline() - row_->top_of_text()) / 2);
941 pain_.line(int(last_strikeout_x), middle, int(x_), middle,
942 LColor::strikeout, Painter::line_solid, Painter::line_thin);
943 running_strikeout = false;
946 if (body_pos > 0 && pos == body_pos - 1) {
947 int const lwidth = font_metrics::width(layout->labelsep,
950 x_ += label_hfill_ + lwidth
951 - singleWidth(body_pos - 1);
954 if (pit_->isHfill(pos)) {
957 int const y0 = yo_ + row_->baseline();
958 int const y1 = y0 - defaultRowHeight() / 2;
960 pain_.line(int(x_), y1, int(x_), y0,
961 LColor::added_space);
963 if (hfillExpansion(text_, row_, pos)) {
964 int const y2 = (y0 + y1) / 2;
966 if (pos >= body_pos) {
967 pain_.line(int(x_), y2,
968 int(x_ + hfill_), y2,
970 Painter::line_onoffdash);
973 pain_.line(int(x_), y2,
974 int(x_ + label_hfill_), y2,
976 Painter::line_onoffdash);
979 pain_.line(int(x_), y1,
981 LColor::added_space);
985 } else if (pit_->isSeparator(pos)) {
986 x_ += singleWidth(pos);
995 // if we reach the end of a struck out range, paint it
996 if (running_strikeout) {
997 int const middle = yo_ + row_->top_of_text()
998 + ((row_->baseline() - row_->top_of_text()) / 2);
999 pain_.line(int(last_strikeout_x), middle, int(x_), middle,
1000 LColor::strikeout, Painter::line_solid, Painter::line_thin);
1001 running_strikeout = false;
1007 void RowPainter::paint()
1009 width_ = text_.isInInset()
1010 ? text_.inset_owner->textWidth(perv(bv_), true) : bv_.workWidth();
1012 // FIXME: must be a cleaner way here. Aren't these calculations
1013 // belonging to row metrics ?
1014 text_.prepareToPrint(row_, x_, separator_, hfill_, label_hfill_);
1016 // FIXME: what is this fixing ?
1017 if (text_.isInInset() && (x_ < 0))
1021 // If we're *not* at the top-level of rows, then the
1022 // background has already been cleared.
1023 if (&text_ == bv_.text)
1026 // paint the selection background
1027 if (text_.selection.set()) {
1031 // vertical lines for appendix
1034 // environment depth brackets
1040 if (row_->isParStart()) {
1044 if (isParEnd(text_, row_)) {
1056 int getLengthMarkerHeight(BufferView const & bv, VSpace const & vsp)
1058 if (vsp.kind() == VSpace::NONE)
1061 int const arrow_size = 4;
1062 int const space_size = int(vsp.inPixels(bv));
1066 int const min_size = max(3 * arrow_size,
1067 font_metrics::maxAscent(font)
1068 + font_metrics::maxDescent(font));
1070 if (vsp.length().len().value() < 0.0)
1073 return max(min_size, space_size);
1077 void paintRows(BufferView const & bv, LyXText const & text,
1078 RowList::iterator rit, int y_offset, int x_offset, int y)
1080 RowPainter painter(bv, text, rit, y_offset, x_offset, y);