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"
25 #include "BufferView.h"
31 #include "rowpainter.h"
33 #include "lyxrow_funcs.h"
34 #include "metricsinfo.h"
38 using namespace lyx::support;
44 extern int PAPER_MARGIN;
45 extern int CHANGEBAR_MARGIN;
46 extern int LEFT_MARGIN;
50 // "temporary". We'll never get to use more
51 // references until we start adding hacks like
52 // these until other places catch up.
53 BufferView * perv(BufferView const & bv)
55 return const_cast<BufferView *>(&bv);
59 * A class used for painting an individual row of text.
63 /// initialise painter
64 RowPainter(BufferView const & bv, LyXText const & text,
65 ParagraphList::iterator pit,
66 RowList::iterator rit, int y_offset, int x_offset, int y);
71 // paint various parts
72 void paintBackground();
73 void paintSelection();
76 void paintChangeBar();
79 void paintForeignMark(double orig_x, LyXFont const & orig_font);
80 void paintHebrewComposeChar(lyx::pos_type & vpos);
81 void paintArabicComposeChar(lyx::pos_type & vpos);
82 void paintChars(lyx::pos_type & vpos, bool hebrew, bool arabic);
83 int paintPageBreak(string const & label, int y);
84 int paintAppendixStart(int y);
85 int paintLengthMarker(string const & prefix, VSpace const & vsp, int start);
87 void paintFromPos(lyx::pos_type & vpos);
88 void paintInset(lyx::pos_type const pos);
90 /// return left margin
91 int leftMargin() const;
93 /// return the font at the given pos
94 LyXFont const getFont(lyx::pos_type pos) const;
96 /// return the label font for this row
97 LyXFont const getLabelFont() const;
99 char const transformChar(char c, lyx::pos_type pos) const;
101 /// return pixel width for the given pos
102 int singleWidth(lyx::pos_type pos) const;
103 int singleWidth(lyx::pos_type pos, char c) const;
105 /// bufferview to paint on
106 BufferView const & bv_;
111 /// LyXText for the row
112 LyXText const & text_;
115 RowList::iterator row_;
118 mutable ParagraphList::iterator pit_;
132 RowPainter::RowPainter(BufferView const & bv, LyXText const & text,
133 ParagraphList::iterator pit, RowList::iterator rit,
134 int y_offset, int x_offset, int y)
135 : bv_(bv), pain_(bv_.painter()), text_(text), row_(rit),
136 pit_(pit), xo_(x_offset), yo_(y_offset), y_(y)
141 LyXFont const RowPainter::getFont(pos_type pos) const
143 return text_.getFont(pit_, pos);
147 int RowPainter::singleWidth(lyx::pos_type pos) const
149 return text_.singleWidth(pit_, pos);
153 int RowPainter::singleWidth(lyx::pos_type pos, char c) const
155 LyXFont const & font = text_.getFont(pit_, pos);
156 return text_.singleWidth(pit_, pos, c, font);
160 LyXFont const RowPainter::getLabelFont() const
162 return text_.getLabelFont(pit_);
166 char const RowPainter::transformChar(char c, lyx::pos_type pos) const
168 return text_.transformChar(c, *pit_, pos);
172 int RowPainter::leftMargin() const
174 return text_.leftMargin(pit_, *row_);
178 void RowPainter::paintInset(pos_type const pos)
180 InsetOld * inset = const_cast<InsetOld*>(pit_->getInset(pos));
184 PainterInfo pi(perv(bv_));
185 pi.base.font = getFont(pos);
186 inset->draw(pi, int(x_), yo_ + row_->baseline());
187 x_ += inset->width();
191 void RowPainter::paintHebrewComposeChar(pos_type & vpos)
193 pos_type pos = text_.vis2log(vpos);
198 char c = pit_->getChar(pos);
202 LyXFont const & font = getFont(pos);
203 int const width = font_metrics::width(c, font);
206 for (pos_type i = pos - 1; i >= 0; --i) {
207 c = pit_->getChar(i);
208 if (!Encodings::IsComposeChar_hebrew(c)) {
209 if (IsPrintableNonspace(c)) {
213 dx = (c == 'ø' || c == 'ã')
215 : (width2 - width) / 2;
222 pain_.text(int(x_) + dx, yo_ + row_->baseline(), str, font);
226 void RowPainter::paintArabicComposeChar(pos_type & vpos)
228 pos_type pos = text_.vis2log(vpos);
232 char c = pit_->getChar(pos);
233 c = transformChar(c, pos);
237 LyXFont const & font = getFont(pos);
238 int const width = font_metrics::width(c, font);
241 for (pos_type i = pos - 1; i >= 0; --i) {
242 c = pit_->getChar(i);
243 if (!Encodings::IsComposeChar_arabic(c)) {
244 if (IsPrintableNonspace(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_.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_.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))
291 if (hebrew && Encodings::IsComposeChar_hebrew(c))
294 if (orig_font != getFont(pos))
298 c = transformChar(c, pos);
303 if (prev_struckout) {
304 orig_font.setColor(LColor::strikeout);
305 } else if (prev_newtext) {
306 orig_font.setColor(LColor::newtext);
309 // Draw text and set the new x position
310 //lyxerr << "paint row: yo_ " << yo_ << " baseline: " << row_->baseline()
312 pain_.text(int(x_), yo_ + row_->baseline(), str, orig_font);
313 x_ += font_metrics::width(str, orig_font);
317 void RowPainter::paintForeignMark(double orig_x, LyXFont const & orig_font)
319 if (!lyxrc.mark_foreign_language)
321 if (orig_font.language() == latex_language)
323 if (orig_font.language() == bv_.buffer()->params.language)
326 int const y = yo_ + row_->baseline() + 1;
327 pain_.line(int(orig_x), y, int(x_), y, LColor::language);
331 void RowPainter::paintFromPos(pos_type & vpos)
333 pos_type const pos = text_.vis2log(vpos);
335 LyXFont const & orig_font = getFont(pos);
337 double const orig_x = x_;
339 char const c = pit_->getChar(pos);
341 if (IsInsetChar(c)) {
344 paintForeignMark(orig_x, orig_font);
348 // usual characters, no insets
350 // special case languages
351 bool const hebrew = (orig_font.language()->lang() == "hebrew");
353 orig_font.language()->lang() == "arabic" &&
354 (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
355 lyxrc.font_norm_type == LyXRC::ISO_10646_1);
357 // draw as many chars as we can
358 if ((!hebrew && !arabic)
359 || (hebrew && !Encodings::IsComposeChar_hebrew(c))
360 || (arabic && !Encodings::IsComposeChar_arabic(c))) {
361 paintChars(vpos, hebrew, arabic);
363 paintHebrewComposeChar(vpos);
365 paintArabicComposeChar(vpos);
368 paintForeignMark(orig_x, orig_font);
374 void RowPainter::paintBackground()
376 int const x = int(xo_);
377 int const y = yo_ < 0 ? 0 : yo_;
378 int const h = yo_ < 0 ? row_->height() + yo_ : row_->height();
379 pain_.fillRectangle(x, y, width_, h, text_.backgroundColor());
383 void RowPainter::paintSelection()
385 bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params);
387 // the current selection
388 int const startx = text_.selection.start.x();
389 int const endx = text_.selection.end.x();
390 int const starty = text_.selection.start.y();
391 int const endy = text_.selection.end.y();
392 RowList::iterator startrow = text_.getRow(text_.selection.start);
393 RowList::iterator endrow = text_.getRow(text_.selection.end);
395 if (text_.bidi_same_direction) {
399 int h = row_->height();
401 if (startrow == row_ && endrow == row_) {
403 x = int(xo_) + startx;
405 pain_.fillRectangle(x, y, w, h, LColor::selection);
409 pain_.fillRectangle(x, y, w, h, LColor::selection);
411 } else if (startrow == row_) {
412 int const x = is_rtl ? int(xo_) : int(xo_ + startx);
413 int const w = is_rtl ? startx : (width_ - startx);
414 pain_.fillRectangle(x, y, w, h, LColor::selection);
415 } else if (endrow == row_) {
416 int const x = is_rtl ? int(xo_ + endx) : int(xo_);
417 int const w = is_rtl ? (width_ - endx) : endx;
418 pain_.fillRectangle(x, y, w, h, LColor::selection);
419 } else if (y_ > starty && y_ < endy) {
420 pain_.fillRectangle(int(xo_), y, width_, h, LColor::selection);
423 } else if (startrow != row_ && endrow != row_) {
424 if (y_ > starty && y_ < endy) {
426 int h = row_->height();
427 pain_.fillRectangle(int(xo_), yo_, w, h, LColor::selection);
432 if ((startrow != row_ && !is_rtl) || (endrow != row_ && is_rtl))
433 pain_.fillRectangle(int(xo_), yo_,
434 int(x_), row_->height(), LColor::selection);
436 pos_type const body_pos = pit_->beginningOfBody();
437 pos_type const last = lastPos(*pit_, row_);
440 for (pos_type vpos = row_->pos(); vpos <= last; ++vpos) {
441 pos_type pos = text_.vis2log(vpos);
442 double const old_tmpx = tmpx;
443 if (body_pos > 0 && pos == body_pos - 1) {
444 LyXLayout_ptr const & layout = pit_->layout();
445 LyXFont const lfont = getLabelFont();
447 tmpx += label_hfill_ + font_metrics::width(layout->labelsep, lfont);
449 if (pit_->isLineSeparator(body_pos - 1))
450 tmpx -= singleWidth(body_pos - 1);
453 if (hfillExpansion(*pit_, row_, pos)) {
454 tmpx += singleWidth(pos);
458 tmpx += label_hfill_;
461 else if (pit_->isSeparator(pos)) {
462 tmpx += singleWidth(pos);
466 tmpx += singleWidth(pos);
469 if ((startrow != row_ || text_.selection.start.pos() <= pos) &&
470 (endrow != row_ || pos < text_.selection.end.pos())) {
471 // Here we do not use x_ as xo_ was added to x_.
472 pain_.fillRectangle(int(old_tmpx), yo_,
473 int(tmpx - old_tmpx + 1),
474 row_->height(), LColor::selection);
478 if ((startrow != row_ && is_rtl) || (endrow != row_ && !is_rtl)) {
479 pain_.fillRectangle(int(xo_ + tmpx),
480 yo_, int(bv_.workWidth() - tmpx),
481 row_->height(), LColor::selection);
486 void RowPainter::paintChangeBar()
488 pos_type const start = row_->pos();
489 pos_type const end = lastPos(*pit_, row_);
491 if (!pit_->isChanged(start, end))
494 int const height = (row_ == text_.lastRow())
496 : row_->height() + boost::next(row_)->top_of_text();
498 pain_.fillRectangle(4, yo_, 5, height, LColor::changebar);
502 void RowPainter::paintAppendix()
504 if (!pit_->params().appendix())
507 // FIXME: can be just width_ ?
508 int const ww = bv_.workWidth();
512 if (pit_->params().startOfAppendix())
513 y += 2 * defaultRowHeight();
515 pain_.line(1, y, 1, yo_ + row_->height(), LColor::appendix);
516 pain_.line(ww - 2, y, ww - 2, yo_ + row_->height(), LColor::appendix);
520 void RowPainter::paintDepthBar()
522 Paragraph::depth_type const depth = pit_->getDepth();
527 Paragraph::depth_type prev_depth = 0;
528 if (row_ != text_.firstRow()) {
529 ParagraphList::iterator pit2 = pit_;
530 if (row_ == pit2->rows.begin())
532 prev_depth = pit2->getDepth();
535 Paragraph::depth_type next_depth = 0;
536 if (row_ != text_.lastRow()) {
537 ParagraphList::iterator pit2 = pit_;
538 if (boost::next(row_) == pit2->rows.end())
540 next_depth = pit2->getDepth();
543 for (Paragraph::depth_type i = 1; i <= depth; ++i) {
544 int const w = PAPER_MARGIN / 5;
545 int x = int(w * i + xo_);
546 // only consider the changebar space if we're drawing outer left
548 x += CHANGEBAR_MARGIN;
549 int const h = yo_ + row_->height() - 1 - (i - next_depth - 1) * 3;
551 pain_.line(x, yo_, x, h, LColor::depthbar);
554 pain_.fillRectangle(x, yo_, w, 2, LColor::depthbar);
556 pain_.fillRectangle(x, h, w, 2, LColor::depthbar);
561 int RowPainter::paintLengthMarker(string const & prefix, VSpace const & vsp, int start)
563 if (vsp.kind() == VSpace::NONE)
566 int const arrow_size = 4;
567 int const size = getLengthMarkerHeight(bv_, vsp);
568 int const end = start + size;
570 // the label to display (if any)
572 // y-values for top arrow
574 // y-values for bottom arrow
577 str = prefix + " (" + vsp.asLyXCommand() + ")";
579 if (vsp.kind() == VSpace::VFILL) {
583 // adding or removing space
584 bool const added = vsp.kind() != VSpace::LENGTH ||
585 vsp.length().len().value() > 0.0;
586 ty1 = added ? (start + arrow_size) : start;
587 ty2 = added ? start : (start + arrow_size);
588 by1 = added ? (end - arrow_size) : end;
589 by2 = added ? end : (end - arrow_size);
592 int const leftx = int(xo_) + leftMargin();
593 int const midx = leftx + arrow_size;
594 int const rightx = midx + arrow_size;
602 font.setColor(LColor::added_space).decSize().decSize();
603 font_metrics::rectText(str, font, w, a, d);
605 pain_.rectText(leftx + 2 * arrow_size + 5,
606 start + ((end - start) / 2) + d,
610 pain_.line(leftx, ty1, midx, ty2, LColor::added_space);
611 pain_.line(midx, ty2, rightx, ty1, LColor::added_space);
614 pain_.line(leftx, by1, midx, by2, LColor::added_space);
615 pain_.line(midx, by2, rightx, by1, LColor::added_space);
618 pain_.line(midx, ty2, midx, by2, LColor::added_space);
624 int RowPainter::paintPageBreak(string const & label, int y)
627 pb_font.setColor(LColor::pagebreak).decSize();
632 font_metrics::rectText(label, pb_font, w, a, d);
634 int const text_start = int(xo_ + (width_ - w) / 2);
635 int const text_end = text_start + w;
637 pain_.rectText(text_start, y + d, label, pb_font);
639 pain_.line(int(xo_), y, text_start, y,
640 LColor::pagebreak, Painter::line_onoffdash);
641 pain_.line(text_end, y, int(xo_ + width_), y,
642 LColor::pagebreak, Painter::line_onoffdash);
644 return 3 * defaultRowHeight();
648 int RowPainter::paintAppendixStart(int y)
651 pb_font.setColor(LColor::appendix).decSize();
653 string const label = _("Appendix");
657 font_metrics::rectText(label, pb_font, w, a, d);
659 int const text_start = int(xo_ + (width_ - w) / 2);
660 int const text_end = text_start + w;
662 pain_.rectText(text_start, y + d, label, pb_font);
664 pain_.line(int(xo_ + 1), y, text_start, y, LColor::appendix);
665 pain_.line(text_end, y, int(xo_ + width_ - 2), y, LColor::appendix);
667 return 3 * defaultRowHeight();
671 void RowPainter::paintFirst()
673 ParagraphParameters const & parparams = pit_->params();
677 // start of appendix?
678 if (parparams.startOfAppendix())
679 y_top += paintAppendixStart(yo_ + y_top + 2 * defaultRowHeight());
682 if (row_ == text_.firstRow() && !text_.isInInset())
683 y_top += PAPER_MARGIN;
685 // draw a top pagebreak
686 if (parparams.pagebreakTop())
687 y_top += paintPageBreak(_("Page Break (top)"),
688 yo_ + y_top + 2 * defaultRowHeight());
690 // draw the additional space if needed:
691 y_top += paintLengthMarker(_("Space above"), parparams.spaceTop(),
694 Buffer const & buffer = *bv_.buffer();
696 LyXLayout_ptr const & layout = pit_->layout();
698 if (buffer.params.paragraph_separation == BufferParams::PARSEP_SKIP) {
699 if (pit_ != text_.ownerParagraphs().begin()) {
700 if (layout->latextype == LATEX_PARAGRAPH
701 && !pit_->getDepth()) {
702 y_top += buffer.params.getDefSkip().inPixels(bv_);
704 LyXLayout_ptr const & playout =
705 boost::prior(pit_)->layout();
706 if (playout->latextype == LATEX_PARAGRAPH
707 && !boost::prior(pit_)->getDepth()) {
708 // is it right to use defskip here, too? (AS)
709 y_top += buffer.params.getDefSkip().inPixels(bv_);
715 int const ww = bv_.workWidth();
718 if (parparams.lineTop()) {
719 int const asc = font_metrics::ascent('x', getFont(0));
723 int const w = (text_.isInInset() ? text_.inset_owner->width() : ww);
724 int const xp = static_cast<int>(text_.isInInset() ? xo_ : 0);
725 pain_.line(xp, yo_ + y_top, xp + w, yo_ + y_top,
726 LColor::topline, Painter::line_solid,
727 Painter::line_thick);
732 bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params);
734 // should we print a label?
735 if (layout->labeltype >= LABEL_STATIC
736 && (layout->labeltype != LABEL_STATIC
737 || layout->latextype != LATEX_ENVIRONMENT
738 || isFirstInSequence(pit_, text_.ownerParagraphs()))) {
740 LyXFont font = getLabelFont();
741 if (!pit_->getLabelstring().empty()) {
743 string const str = pit_->getLabelstring();
745 // this is special code for the chapter layout. This is
746 // printed in an extra row and has a pagebreak at
748 if (layout->labeltype == LABEL_COUNTER_CHAPTER) {
749 if (buffer.params.secnumdepth >= 0) {
750 float spacing_val = 1.0;
751 if (!parparams.spacing().isDefault()) {
752 spacing_val = parparams.spacing().getValue();
754 spacing_val = buffer.params.spacing.getValue();
758 int(font_metrics::maxDescent(font) * layout->spacing.getValue() * spacing_val)
759 + int(layout->parsep) * defaultRowHeight();
762 x = ww - leftMargin() -
763 font_metrics::width(str, font);
767 yo_ + row_->baseline() -
768 row_->ascent_of_text() - maxdesc,
773 x = ww - leftMargin()
774 + font_metrics::width(layout->labelsep, font);
776 x = x_ - font_metrics::width(layout->labelsep, font)
777 - font_metrics::width(str, font);
780 pain_.text(int(x), yo_ + row_->baseline(), str, font);
784 // the labels at the top of an environment.
785 // More or less for bibliography
786 } else if (isFirstInSequence(pit_, text_.ownerParagraphs()) &&
787 (layout->labeltype == LABEL_TOP_ENVIRONMENT ||
788 layout->labeltype == LABEL_BIBLIO ||
789 layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)) {
790 LyXFont font = getLabelFont();
791 if (!pit_->getLabelstring().empty()) {
792 string const str = pit_->getLabelstring();
793 float spacing_val = 1.0;
794 if (!parparams.spacing().isDefault()) {
795 spacing_val = parparams.spacing().getValue();
797 spacing_val = buffer.params.spacing.getValue();
801 int(font_metrics::maxDescent(font) * layout->spacing.getValue() * spacing_val
802 + (layout->labelbottomsep * defaultRowHeight()));
805 if (layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
806 x = ((is_rtl ? leftMargin() : x_)
807 + ww - text_.rightMargin(pit_, *bv_.buffer(), *row_)) / 2;
808 x -= font_metrics::width(str, font) / 2;
810 x = ww - leftMargin() -
811 font_metrics::width(str, font);
814 yo_ + row_->baseline() - row_->ascent_of_text() - maxdesc,
821 void RowPainter::paintLast()
823 ParagraphParameters const & parparams = pit_->params();
824 int y_bottom = row_->height() - 1;
827 if (row_ == text_.lastRow() && !text_.isInInset())
828 y_bottom -= PAPER_MARGIN;
830 int const ww = bv_.workWidth();
832 // draw a bottom pagebreak
833 if (parparams.pagebreakBottom()) {
834 y_bottom -= paintPageBreak(_("Page Break (bottom)"),
835 yo_ + y_bottom - 2 * defaultRowHeight());
838 // draw the additional space if needed:
839 int const height = getLengthMarkerHeight(bv_, parparams.spaceBottom());
840 y_bottom -= paintLengthMarker(_("Space below"), parparams.spaceBottom(),
841 yo_ + y_bottom - height);
843 // draw a bottom line
844 if (parparams.lineBottom()) {
845 int const asc = font_metrics::ascent('x',
846 getFont(max(pos_type(0), pit_->size() - 1)));
850 int const w = text_.isInInset() ? text_.inset_owner->width() : ww;
851 int const xp = int(text_.isInInset() ? xo_ : 0);
852 int const y = yo_ + y_bottom;
853 pain_.line(xp, y, xp + w, y, LColor::topline, Painter::line_solid,
854 Painter::line_thick);
859 bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params);
860 int const endlabel = getEndLabel(pit_, text_.ownerParagraphs());
865 case END_LABEL_FILLED_BOX:
867 LyXFont const font = getLabelFont();
868 int const size = int(0.75 * font_metrics::maxAscent(font));
869 int const y = (yo_ + row_->baseline()) - size;
870 int x = is_rtl ? LEFT_MARGIN : ww - PAPER_MARGIN - size;
872 if (row_->fill() <= size)
873 x += (size - row_->fill() + 1) * (is_rtl ? -1 : 1);
875 if (endlabel == END_LABEL_BOX)
876 pain_.rectangle(x, y, size, size, LColor::eolmarker);
878 pain_.fillRectangle(x, y, size, size, LColor::eolmarker);
881 case END_LABEL_STATIC:
883 LyXFont font = getLabelFont();
884 string const & str = pit_->layout()->endlabelstring();
885 double const x = is_rtl ?
886 x_ - font_metrics::width(str, font)
887 : ww - text_.rightMargin(pit_, *bv_.buffer(), *row_) - row_->fill();
888 pain_.text(int(x), yo_ + row_->baseline(), str, font);
891 case END_LABEL_NO_LABEL:
897 void RowPainter::paintText()
899 pos_type const last = lastPos(*pit_, row_);
900 pos_type body_pos = pit_->beginningOfBody();
902 (body_pos - 1 > last || !pit_->isLineSeparator(body_pos - 1))) {
906 LyXLayout_ptr const & layout = pit_->layout();
908 bool running_strikeout = false;
909 bool is_struckout = false;
910 int last_strikeout_x = 0;
912 pos_type vpos = row_->pos();
913 while (vpos <= last) {
914 if (x_ > bv_.workWidth())
916 pos_type pos = text_.vis2log(vpos);
918 if (pos >= pit_->size()) {
923 if (x_ + singleWidth(pos) < 0) {
924 x_ += singleWidth(pos);
929 is_struckout = isDeletedText(*pit_, pos);
931 if (is_struckout && !running_strikeout) {
932 running_strikeout = true;
933 last_strikeout_x = int(x_);
936 bool const highly_editable_inset = pit_->isInset(pos)
937 && isHighlyEditableInset(pit_->getInset(pos));
939 // if we reach the end of a struck out range, paint it
940 // we also don't paint across things like tables
941 if (running_strikeout && (highly_editable_inset || !is_struckout)) {
942 int const middle = yo_ + row_->top_of_text()
943 + (row_->baseline() - row_->top_of_text()) / 2;
944 pain_.line(last_strikeout_x, middle, int(x_), middle,
945 LColor::strikeout, Painter::line_solid, Painter::line_thin);
946 running_strikeout = false;
949 if (body_pos > 0 && pos == body_pos - 1) {
950 int const lwidth = font_metrics::width(layout->labelsep,
953 x_ += label_hfill_ + lwidth - singleWidth(body_pos - 1);
956 if (pit_->isHfill(pos)) {
959 int const y0 = yo_ + row_->baseline();
960 int const y1 = y0 - defaultRowHeight() / 2;
962 pain_.line(int(x_), y1, int(x_), y0, LColor::added_space);
964 if (hfillExpansion(*pit_, row_, pos)) {
965 int const y2 = (y0 + y1) / 2;
967 if (pos >= body_pos) {
968 pain_.line(int(x_), y2, int(x_ + hfill_), y2,
970 Painter::line_onoffdash);
973 pain_.line(int(x_), y2, int(x_ + label_hfill_), y2,
975 Painter::line_onoffdash);
978 pain_.line(int(x_), y1, int(x_), y0, LColor::added_space);
982 } else if (pit_->isSeparator(pos)) {
983 x_ += singleWidth(pos);
992 // if we reach the end of a struck out range, paint it
993 if (running_strikeout) {
994 int const middle = yo_ + row_->top_of_text()
995 + ((row_->baseline() - row_->top_of_text()) / 2);
996 pain_.line(last_strikeout_x, middle, int(x_), middle,
997 LColor::strikeout, Painter::line_solid, Painter::line_thin);
998 running_strikeout = false;
1003 void RowPainter::paint()
1005 width_ = text_.workWidth();
1007 separator_ = row_->fill_separator();
1008 hfill_ = row_->fill_hfill();
1009 label_hfill_ = row_->fill_label_hfill();
1011 // FIXME: what is this fixing ?
1012 if (text_.isInInset() && x_ < 0)
1016 // If we're *not* at the top-level of rows, then the
1017 // background has already been cleared.
1018 if (&text_ == bv_.text)
1021 // paint the selection background
1022 if (text_.selection.set())
1025 // vertical lines for appendix
1028 // environment depth brackets
1034 if (row_->isParStart())
1037 if (isParEnd(*pit_, row_))
1045 int paintRows(BufferView const & bv, LyXText const & text,
1046 ParagraphList::iterator pit, RowList::iterator rit,
1047 int xo, int y, int yf, int yo)
1049 //lyxerr << " paintRows: rit: " << &*rit << endl;
1050 //const_cast<LyXText&>(text).updateRowPositions();
1051 int const yy = yf - y;
1052 int const y2 = bv.painter().paperHeight();
1054 ParagraphList::iterator end = text.ownerParagraphs().end();
1055 bool active = false;
1057 for ( ; pit != end; ++pit) {
1058 RowList::iterator row = pit->rows.begin();
1059 RowList::iterator rend = pit->rows.end();
1061 for ( ; row != rend; ++row) {
1065 RowPainter painter(bv, text, pit, row, y + yo, xo, y + bv.top_y());
1071 //lyxerr << " paintRows: row: " << &*row << " ignored" << endl;
1082 int paintText(BufferView & bv)
1084 int const topy = bv.top_y();
1085 ParagraphList::iterator pit;
1086 RowList::iterator rit = bv.text->getRowNearY(topy, pit);
1087 int y = rit->y() - topy;
1088 return paintRows(bv, *bv.text, pit, rit, 0, y, y, 0);
1092 void paintTextInset(BufferView & bv, LyXText & text, int x, int baseline)
1094 RowList::iterator rit = text.firstRow();
1095 RowList::iterator end = text.endRow();
1096 ParagraphList::iterator pit = text.ownerParagraphs().begin();
1098 int y_offset = baseline - rit->ascent_of_text();
1100 while (rit != end && y + rit->height() <= 0) {
1102 text.nextRow(pit, rit);
1105 paintRows(bv, text, pit, rit, x, 0, y, y);
1107 paintRows(bv, text, pit, rit, x, 0, y_offset, y_offset);
1111 int getLengthMarkerHeight(BufferView const & bv, VSpace const & vsp)
1113 if (vsp.kind() == VSpace::NONE)
1116 int const arrow_size = 4;
1117 int const space_size = vsp.inPixels(bv);
1121 int const min_size = max(3 * arrow_size,
1122 font_metrics::maxAscent(font)
1123 + font_metrics::maxDescent(font));
1125 if (vsp.length().len().value() < 0.0)
1128 return max(min_size, space_size);