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"
17 #include "bufferparams.h"
18 #include "BufferView.h"
24 #include "lyxrow_funcs.h"
25 #include "metricsinfo.h"
26 #include "paragraph_funcs.h"
27 #include "ParagraphParameters.h"
30 #include "frontends/font_metrics.h"
31 #include "frontends/Painter.h"
33 #include "insets/insettext.h"
35 #include "support/textutils.h"
41 extern int PAPER_MARGIN;
42 extern int CHANGEBAR_MARGIN;
43 extern int LEFT_MARGIN;
47 // "temporary". We'll never get to use more
48 // references until we start adding hacks like
49 // these until other places catch up.
50 BufferView * perv(BufferView const & bv)
52 return const_cast<BufferView *>(&bv);
56 * A class used for painting an individual row of text.
60 /// initialise painter
61 RowPainter(BufferView const & bv, LyXText const & text,
62 ParagraphList::iterator pit,
63 RowList::iterator rit, int y_offset, int x_offset, int y);
68 // paint various parts
69 void paintBackground();
70 void paintSelection();
73 void paintChangeBar();
76 void paintForeignMark(double orig_x, LyXFont const & orig_font);
77 void paintHebrewComposeChar(lyx::pos_type & vpos);
78 void paintArabicComposeChar(lyx::pos_type & vpos);
79 void paintChars(lyx::pos_type & vpos, bool hebrew, bool arabic);
80 int paintPageBreak(string const & label, int y);
81 int paintAppendixStart(int y);
82 int paintLengthMarker(string const & prefix, VSpace const & vsp, int start);
84 void paintFromPos(lyx::pos_type & vpos);
85 void paintInset(lyx::pos_type const pos);
87 /// return left margin
88 int leftMargin() const;
90 /// return the font at the given pos
91 LyXFont const getFont(lyx::pos_type pos) const;
93 /// return the label font for this row
94 LyXFont const getLabelFont() const;
96 char const transformChar(char c, lyx::pos_type pos) const;
98 /// return pixel width for the given pos
99 int singleWidth(lyx::pos_type pos) const;
100 int singleWidth(lyx::pos_type pos, char c) const;
102 /// bufferview to paint on
103 BufferView const & bv_;
108 /// LyXText for the row
109 LyXText const & text_;
112 RowList::iterator row_;
115 mutable ParagraphList::iterator pit_;
129 RowPainter::RowPainter(BufferView const & bv, LyXText const & text,
130 ParagraphList::iterator pit, RowList::iterator rit,
131 int y_offset, int x_offset, int y)
132 : bv_(bv), pain_(bv_.painter()), text_(text), row_(rit),
133 pit_(pit), xo_(x_offset), yo_(y_offset), y_(y)
138 LyXFont const RowPainter::getFont(pos_type pos) const
140 return text_.getFont(pit_, pos);
144 int RowPainter::singleWidth(lyx::pos_type pos) const
146 return text_.singleWidth(pit_, pos);
150 int RowPainter::singleWidth(lyx::pos_type pos, char c) const
152 LyXFont const & font = text_.getFont(pit_, pos);
153 return text_.singleWidth(pit_, pos, c, font);
157 LyXFont const RowPainter::getLabelFont() const
159 return text_.getLabelFont(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(pit_, *row_);
175 void RowPainter::paintInset(pos_type const pos)
177 InsetOld * inset = const_cast<InsetOld*>(pit_->getInset(pos));
181 PainterInfo pi(perv(bv_));
182 pi.base.font = getFont(pos);
183 inset->draw(pi, int(x_), yo_ + row_->baseline());
184 x_ += inset->width();
188 void RowPainter::paintHebrewComposeChar(pos_type & vpos)
190 pos_type pos = text_.vis2log(vpos);
195 char c = pit_->getChar(pos);
199 LyXFont const & font = getFont(pos);
200 int const width = font_metrics::width(c, font);
203 for (pos_type i = pos - 1; i >= 0; --i) {
204 c = pit_->getChar(i);
205 if (!Encodings::IsComposeChar_hebrew(c)) {
206 if (IsPrintableNonspace(c)) {
210 dx = (c == 'ø' || c == 'ã')
212 : (width2 - width) / 2;
219 pain_.text(int(x_) + dx, yo_ + row_->baseline(), str, font);
223 void RowPainter::paintArabicComposeChar(pos_type & vpos)
225 pos_type pos = text_.vis2log(vpos);
229 char c = pit_->getChar(pos);
230 c = transformChar(c, pos);
234 LyXFont const & font = getFont(pos);
235 int const width = font_metrics::width(c, font);
238 for (pos_type i = pos - 1; i >= 0; --i) {
239 c = pit_->getChar(i);
240 if (!Encodings::IsComposeChar_arabic(c)) {
241 if (IsPrintableNonspace(c)) {
244 dx = (width2 - width) / 2;
250 pain_.text(int(x_) + dx, yo_ + row_->baseline(), str, font);
254 void RowPainter::paintChars(pos_type & vpos, bool hebrew, bool arabic)
256 pos_type pos = text_.vis2log(vpos);
257 pos_type const last = lastPos(*pit_, row_);
258 LyXFont orig_font = getFont(pos);
262 str += pit_->getChar(pos);
264 unsigned char c = str[0];
265 str[0] = transformChar(c, pos);
268 bool prev_struckout(isDeletedText(*pit_, pos));
269 bool prev_newtext(isInsertedText(*pit_, pos));
273 // collect as much similar chars as we can
274 while (vpos <= last && (pos = text_.vis2log(vpos)) >= 0) {
275 char c = pit_->getChar(pos);
277 if (!IsPrintableNonspace(c))
280 if (prev_struckout != isDeletedText(*pit_, pos))
283 if (prev_newtext != isInsertedText(*pit_, pos))
286 if (arabic && Encodings::IsComposeChar_arabic(c))
288 if (hebrew && Encodings::IsComposeChar_hebrew(c))
291 if (orig_font != getFont(pos))
295 c = transformChar(c, pos);
300 if (prev_struckout) {
301 orig_font.setColor(LColor::strikeout);
302 } else if (prev_newtext) {
303 orig_font.setColor(LColor::newtext);
306 // Draw text and set the new x position
307 //lyxerr << "paint row: yo_ " << yo_ << " baseline: " << row_->baseline()
309 pain_.text(int(x_), yo_ + row_->baseline(), str, orig_font);
310 x_ += font_metrics::width(str, orig_font);
314 void RowPainter::paintForeignMark(double orig_x, LyXFont const & orig_font)
316 if (!lyxrc.mark_foreign_language)
318 if (orig_font.language() == latex_language)
320 if (orig_font.language() == bv_.buffer()->params().language)
323 int const y = yo_ + row_->baseline() + 1;
324 pain_.line(int(orig_x), y, int(x_), y, LColor::language);
328 void RowPainter::paintFromPos(pos_type & vpos)
330 pos_type const pos = text_.vis2log(vpos);
332 LyXFont const & orig_font = getFont(pos);
334 double const orig_x = x_;
336 char const c = pit_->getChar(pos);
338 if (IsInsetChar(c)) {
341 paintForeignMark(orig_x, orig_font);
345 // usual characters, no insets
347 // special case languages
348 bool const hebrew = (orig_font.language()->lang() == "hebrew");
350 orig_font.language()->lang() == "arabic" &&
351 (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
352 lyxrc.font_norm_type == LyXRC::ISO_10646_1);
354 // draw as many chars as we can
355 if ((!hebrew && !arabic)
356 || (hebrew && !Encodings::IsComposeChar_hebrew(c))
357 || (arabic && !Encodings::IsComposeChar_arabic(c))) {
358 paintChars(vpos, hebrew, arabic);
360 paintHebrewComposeChar(vpos);
362 paintArabicComposeChar(vpos);
365 paintForeignMark(orig_x, orig_font);
371 void RowPainter::paintBackground()
373 int const x = int(xo_);
374 int const y = yo_ < 0 ? 0 : yo_;
375 int const h = yo_ < 0 ? row_->height() + yo_ : row_->height();
376 pain_.fillRectangle(x, y, width_, h, text_.backgroundColor());
380 void RowPainter::paintSelection()
382 bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params());
384 // the current selection
385 int const startx = text_.selection.start.x();
386 int const endx = text_.selection.end.x();
387 int const starty = text_.selection.start.y();
388 int const endy = text_.selection.end.y();
389 RowList::iterator startrow = text_.getRow(text_.selection.start);
390 RowList::iterator endrow = text_.getRow(text_.selection.end);
392 if (text_.bidi_same_direction) {
396 int h = row_->height();
398 if (startrow == row_ && endrow == row_) {
400 x = int(xo_) + startx;
402 pain_.fillRectangle(x, y, w, h, LColor::selection);
406 pain_.fillRectangle(x, y, w, h, LColor::selection);
408 } else if (startrow == row_) {
409 int const x = is_rtl ? int(xo_) : int(xo_ + startx);
410 int const w = is_rtl ? startx : (width_ - startx);
411 pain_.fillRectangle(x, y, w, h, LColor::selection);
412 } else if (endrow == row_) {
413 int const x = is_rtl ? int(xo_ + endx) : int(xo_);
414 int const w = is_rtl ? (width_ - endx) : endx;
415 pain_.fillRectangle(x, y, w, h, LColor::selection);
416 } else if (y_ > starty && y_ < endy) {
417 pain_.fillRectangle(int(xo_), y, width_, h, LColor::selection);
420 } else if (startrow != row_ && endrow != row_) {
421 if (y_ > starty && y_ < endy) {
423 int h = row_->height();
424 pain_.fillRectangle(int(xo_), yo_, w, h, LColor::selection);
429 if ((startrow != row_ && !is_rtl) || (endrow != row_ && is_rtl))
430 pain_.fillRectangle(int(xo_), yo_,
431 int(x_), row_->height(), LColor::selection);
433 pos_type const body_pos = pit_->beginningOfBody();
434 pos_type const last = lastPos(*pit_, row_);
437 for (pos_type vpos = row_->pos(); vpos <= last; ++vpos) {
438 pos_type pos = text_.vis2log(vpos);
439 double const old_tmpx = tmpx;
440 if (body_pos > 0 && pos == body_pos - 1) {
441 LyXLayout_ptr const & layout = pit_->layout();
442 LyXFont const lfont = getLabelFont();
444 tmpx += label_hfill_ + font_metrics::width(layout->labelsep, lfont);
446 if (pit_->isLineSeparator(body_pos - 1))
447 tmpx -= singleWidth(body_pos - 1);
450 if (hfillExpansion(*pit_, row_, pos)) {
451 tmpx += singleWidth(pos);
455 tmpx += label_hfill_;
458 else if (pit_->isSeparator(pos)) {
459 tmpx += singleWidth(pos);
463 tmpx += singleWidth(pos);
466 if ((startrow != row_ || text_.selection.start.pos() <= pos) &&
467 (endrow != row_ || pos < text_.selection.end.pos())) {
468 // Here we do not use x_ as xo_ was added to x_.
469 pain_.fillRectangle(int(old_tmpx), yo_,
470 int(tmpx - old_tmpx + 1),
471 row_->height(), LColor::selection);
475 if ((startrow != row_ && is_rtl) || (endrow != row_ && !is_rtl)) {
476 pain_.fillRectangle(int(xo_ + tmpx),
477 yo_, int(bv_.workWidth() - tmpx),
478 row_->height(), LColor::selection);
483 void RowPainter::paintChangeBar()
485 pos_type const start = row_->pos();
486 pos_type const end = lastPos(*pit_, row_);
488 if (!pit_->isChanged(start, end))
491 int const height = (row_ == text_.lastRow())
493 : row_->height() + boost::next(row_)->top_of_text();
495 pain_.fillRectangle(4, yo_, 5, height, LColor::changebar);
499 void RowPainter::paintAppendix()
501 if (!pit_->params().appendix())
504 // FIXME: can be just width_ ?
505 int const ww = bv_.workWidth();
509 if (pit_->params().startOfAppendix())
510 y += 2 * defaultRowHeight();
512 pain_.line(1, y, 1, yo_ + row_->height(), LColor::appendix);
513 pain_.line(ww - 2, y, ww - 2, yo_ + row_->height(), LColor::appendix);
517 void RowPainter::paintDepthBar()
519 Paragraph::depth_type const depth = pit_->getDepth();
524 Paragraph::depth_type prev_depth = 0;
525 if (row_ != text_.firstRow()) {
526 ParagraphList::iterator pit2 = pit_;
527 if (row_ == pit2->rows.begin())
529 prev_depth = pit2->getDepth();
532 Paragraph::depth_type next_depth = 0;
533 if (row_ != text_.lastRow()) {
534 ParagraphList::iterator pit2 = pit_;
535 if (boost::next(row_) == pit2->rows.end())
537 next_depth = pit2->getDepth();
540 for (Paragraph::depth_type i = 1; i <= depth; ++i) {
541 int const w = PAPER_MARGIN / 5;
542 int x = int(w * i + xo_);
543 // only consider the changebar space if we're drawing outer left
545 x += CHANGEBAR_MARGIN;
546 int const h = yo_ + row_->height() - 1 - (i - next_depth - 1) * 3;
548 pain_.line(x, yo_, x, h, LColor::depthbar);
551 pain_.fillRectangle(x, yo_, w, 2, LColor::depthbar);
553 pain_.fillRectangle(x, h, w, 2, LColor::depthbar);
558 int RowPainter::paintLengthMarker(string const & prefix, VSpace const & vsp, int start)
560 if (vsp.kind() == VSpace::NONE)
563 int const arrow_size = 4;
564 int const size = getLengthMarkerHeight(bv_, vsp);
565 int const end = start + size;
567 // the label to display (if any)
569 // y-values for top arrow
571 // y-values for bottom arrow
574 str = prefix + " (" + vsp.asLyXCommand() + ")";
576 if (vsp.kind() == VSpace::VFILL) {
580 // adding or removing space
581 bool const added = vsp.kind() != VSpace::LENGTH ||
582 vsp.length().len().value() > 0.0;
583 ty1 = added ? (start + arrow_size) : start;
584 ty2 = added ? start : (start + arrow_size);
585 by1 = added ? (end - arrow_size) : end;
586 by2 = added ? end : (end - arrow_size);
589 int const leftx = int(xo_) + leftMargin();
590 int const midx = leftx + arrow_size;
591 int const rightx = midx + arrow_size;
599 font.setColor(LColor::added_space).decSize().decSize();
600 font_metrics::rectText(str, font, w, a, d);
602 pain_.rectText(leftx + 2 * arrow_size + 5,
603 start + ((end - start) / 2) + d,
607 pain_.line(leftx, ty1, midx, ty2, LColor::added_space);
608 pain_.line(midx, ty2, rightx, ty1, LColor::added_space);
611 pain_.line(leftx, by1, midx, by2, LColor::added_space);
612 pain_.line(midx, by2, rightx, by1, LColor::added_space);
615 pain_.line(midx, ty2, midx, by2, LColor::added_space);
621 int RowPainter::paintPageBreak(string const & label, int y)
624 pb_font.setColor(LColor::pagebreak).decSize();
629 font_metrics::rectText(label, pb_font, w, a, d);
631 int const text_start = int(xo_ + (width_ - w) / 2);
632 int const text_end = text_start + w;
634 pain_.rectText(text_start, y + d, label, pb_font);
636 pain_.line(int(xo_), y, text_start, y,
637 LColor::pagebreak, Painter::line_onoffdash);
638 pain_.line(text_end, y, int(xo_ + width_), y,
639 LColor::pagebreak, Painter::line_onoffdash);
641 return 3 * defaultRowHeight();
645 int RowPainter::paintAppendixStart(int y)
648 pb_font.setColor(LColor::appendix).decSize();
650 string const label = _("Appendix");
654 font_metrics::rectText(label, pb_font, w, a, d);
656 int const text_start = int(xo_ + (width_ - w) / 2);
657 int const text_end = text_start + w;
659 pain_.rectText(text_start, y + d, label, pb_font);
661 pain_.line(int(xo_ + 1), y, text_start, y, LColor::appendix);
662 pain_.line(text_end, y, int(xo_ + width_ - 2), y, LColor::appendix);
664 return 3 * defaultRowHeight();
668 void RowPainter::paintFirst()
670 ParagraphParameters const & parparams = pit_->params();
674 // start of appendix?
675 if (parparams.startOfAppendix())
676 y_top += paintAppendixStart(yo_ + y_top + 2 * defaultRowHeight());
679 if (row_ == text_.firstRow() && !text_.isInInset())
680 y_top += PAPER_MARGIN;
682 // draw a top pagebreak
683 if (parparams.pagebreakTop())
684 y_top += paintPageBreak(_("Page Break (top)"),
685 yo_ + y_top + 2 * defaultRowHeight());
687 // draw the additional space if needed:
688 y_top += paintLengthMarker(_("Space above"), parparams.spaceTop(),
691 Buffer const & buffer = *bv_.buffer();
693 LyXLayout_ptr const & layout = pit_->layout();
695 if (buffer.params().paragraph_separation == BufferParams::PARSEP_SKIP) {
696 if (pit_ != text_.ownerParagraphs().begin()) {
697 if (layout->latextype == LATEX_PARAGRAPH
698 && !pit_->getDepth()) {
699 y_top += buffer.params().getDefSkip().inPixels(bv_);
701 LyXLayout_ptr const & playout =
702 boost::prior(pit_)->layout();
703 if (playout->latextype == LATEX_PARAGRAPH
704 && !boost::prior(pit_)->getDepth()) {
705 // is it right to use defskip here, too? (AS)
706 y_top += buffer.params().getDefSkip().inPixels(bv_);
712 int const ww = bv_.workWidth();
715 if (parparams.lineTop()) {
716 int const asc = font_metrics::ascent('x', getFont(0));
720 int const w = (text_.isInInset() ? text_.inset_owner->width() : ww);
721 int const xp = static_cast<int>(text_.isInInset() ? xo_ : 0);
722 pain_.line(xp, yo_ + y_top, xp + w, yo_ + y_top,
723 LColor::topline, Painter::line_solid,
724 Painter::line_thick);
729 bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params());
731 // should we print a label?
732 if (layout->labeltype >= LABEL_STATIC
733 && (layout->labeltype != LABEL_STATIC
734 || layout->latextype != LATEX_ENVIRONMENT
735 || isFirstInSequence(pit_, text_.ownerParagraphs()))) {
737 LyXFont font = getLabelFont();
738 if (!pit_->getLabelstring().empty()) {
740 string const str = pit_->getLabelstring();
742 // this is special code for the chapter layout. This is
743 // printed in an extra row and has a pagebreak at
745 if (layout->counter == "chapter") {
746 if (buffer.params().secnumdepth >= 0) {
747 float spacing_val = 1.0;
748 if (!parparams.spacing().isDefault()) {
749 spacing_val = parparams.spacing().getValue();
751 spacing_val = buffer.params().spacing().getValue();
755 int(font_metrics::maxDescent(font) * layout->spacing.getValue() * spacing_val)
756 + int(layout->parsep) * defaultRowHeight();
759 x = ww - leftMargin() -
760 font_metrics::width(str, font);
764 yo_ + row_->baseline() -
765 row_->ascent_of_text() - maxdesc,
770 x = ww - leftMargin()
771 + font_metrics::width(layout->labelsep, font);
773 x = x_ - font_metrics::width(layout->labelsep, font)
774 - font_metrics::width(str, font);
777 pain_.text(int(x), yo_ + row_->baseline(), str, font);
781 // the labels at the top of an environment.
782 // More or less for bibliography
783 } else if (isFirstInSequence(pit_, text_.ownerParagraphs()) &&
784 (layout->labeltype == LABEL_TOP_ENVIRONMENT ||
785 layout->labeltype == LABEL_BIBLIO ||
786 layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)) {
787 LyXFont font = getLabelFont();
788 if (!pit_->getLabelstring().empty()) {
789 string const str = pit_->getLabelstring();
790 float spacing_val = 1.0;
791 if (!parparams.spacing().isDefault()) {
792 spacing_val = parparams.spacing().getValue();
794 spacing_val = buffer.params().spacing().getValue();
798 int(font_metrics::maxDescent(font) * layout->spacing.getValue() * spacing_val
799 + (layout->labelbottomsep * defaultRowHeight()));
802 if (layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
803 x = ((is_rtl ? leftMargin() : x_)
804 + ww - text_.rightMargin(pit_, *bv_.buffer(), *row_)) / 2;
805 x -= font_metrics::width(str, font) / 2;
807 x = ww - leftMargin() -
808 font_metrics::width(str, font);
811 yo_ + row_->baseline() - row_->ascent_of_text() - maxdesc,
818 void RowPainter::paintLast()
820 ParagraphParameters const & parparams = pit_->params();
821 int y_bottom = row_->height() - 1;
824 if (row_ == text_.lastRow() && !text_.isInInset())
825 y_bottom -= PAPER_MARGIN;
827 int const ww = bv_.workWidth();
829 // draw a bottom pagebreak
830 if (parparams.pagebreakBottom()) {
831 y_bottom -= paintPageBreak(_("Page Break (bottom)"),
832 yo_ + y_bottom - 2 * defaultRowHeight());
835 // draw the additional space if needed:
836 int const height = getLengthMarkerHeight(bv_, parparams.spaceBottom());
837 y_bottom -= paintLengthMarker(_("Space below"), parparams.spaceBottom(),
838 yo_ + y_bottom - height);
840 // draw a bottom line
841 if (parparams.lineBottom()) {
842 int const asc = font_metrics::ascent('x',
843 getFont(max(pos_type(0), pit_->size() - 1)));
847 int const w = text_.isInInset() ? text_.inset_owner->width() : ww;
848 int const xp = int(text_.isInInset() ? xo_ : 0);
849 int const y = yo_ + y_bottom;
850 pain_.line(xp, y, xp + w, y, LColor::topline, Painter::line_solid,
851 Painter::line_thick);
856 bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params());
857 int const endlabel = getEndLabel(pit_, text_.ownerParagraphs());
862 case END_LABEL_FILLED_BOX:
864 LyXFont const font = getLabelFont();
865 int const size = int(0.75 * font_metrics::maxAscent(font));
866 int const y = (yo_ + row_->baseline()) - size;
867 int x = is_rtl ? LEFT_MARGIN : ww - PAPER_MARGIN - size;
869 if (row_->fill() <= size)
870 x += (size - row_->fill() + 1) * (is_rtl ? -1 : 1);
872 if (endlabel == END_LABEL_BOX)
873 pain_.rectangle(x, y, size, size, LColor::eolmarker);
875 pain_.fillRectangle(x, y, size, size, LColor::eolmarker);
878 case END_LABEL_STATIC:
880 LyXFont font = getLabelFont();
881 string const & str = pit_->layout()->endlabelstring();
882 double const x = is_rtl ?
883 x_ - font_metrics::width(str, font)
884 : ww - text_.rightMargin(pit_, *bv_.buffer(), *row_) - row_->fill();
885 pain_.text(int(x), yo_ + row_->baseline(), str, font);
888 case END_LABEL_NO_LABEL:
894 void RowPainter::paintText()
896 pos_type const last = lastPos(*pit_, row_);
897 pos_type body_pos = pit_->beginningOfBody();
899 (body_pos - 1 > last || !pit_->isLineSeparator(body_pos - 1))) {
903 LyXLayout_ptr const & layout = pit_->layout();
905 bool running_strikeout = false;
906 bool is_struckout = false;
907 int last_strikeout_x = 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 = int(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(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 - singleWidth(body_pos - 1);
953 if (pit_->isHfill(pos)) {
956 int const y0 = yo_ + row_->baseline();
957 int const y1 = y0 - defaultRowHeight() / 2;
959 pain_.line(int(x_), y1, int(x_), y0, LColor::added_space);
961 if (hfillExpansion(*pit_, row_, pos)) {
962 int const y2 = (y0 + y1) / 2;
964 if (pos >= body_pos) {
965 pain_.line(int(x_), y2, int(x_ + hfill_), y2,
967 Painter::line_onoffdash);
970 pain_.line(int(x_), y2, int(x_ + label_hfill_), y2,
972 Painter::line_onoffdash);
975 pain_.line(int(x_), y1, int(x_), y0, LColor::added_space);
979 } else if (pit_->isSeparator(pos)) {
980 x_ += singleWidth(pos);
989 // if we reach the end of a struck out range, paint it
990 if (running_strikeout) {
991 int const middle = yo_ + row_->top_of_text()
992 + ((row_->baseline() - row_->top_of_text()) / 2);
993 pain_.line(last_strikeout_x, middle, int(x_), middle,
994 LColor::strikeout, Painter::line_solid, Painter::line_thin);
995 running_strikeout = false;
1000 void RowPainter::paint()
1002 width_ = text_.workWidth();
1004 separator_ = row_->fill_separator();
1005 hfill_ = row_->fill_hfill();
1006 label_hfill_ = row_->fill_label_hfill();
1008 // FIXME: what is this fixing ?
1009 if (text_.isInInset() && x_ < 0)
1013 // If we're *not* at the top-level of rows, then the
1014 // background has already been cleared.
1015 if (&text_ == bv_.text)
1018 // paint the selection background
1019 if (text_.selection.set())
1022 // vertical lines for appendix
1025 // environment depth brackets
1031 if (row_->isParStart())
1034 if (isParEnd(*pit_, row_))
1042 int paintRows(BufferView const & bv, LyXText const & text,
1043 ParagraphList::iterator pit, RowList::iterator rit,
1044 int xo, int y, int yf, int yo)
1046 //lyxerr << " paintRows: rit: " << &*rit << endl;
1047 //const_cast<LyXText&>(text).updateRowPositions();
1048 int const yy = yf - y;
1049 int const y2 = bv.painter().paperHeight();
1051 ParagraphList::iterator end = text.ownerParagraphs().end();
1052 bool active = false;
1054 for ( ; pit != end; ++pit) {
1055 RowList::iterator row = pit->rows.begin();
1056 RowList::iterator rend = pit->rows.end();
1058 for ( ; row != rend; ++row) {
1062 RowPainter painter(bv, text, pit, row, y + yo, xo, y + bv.top_y());
1068 //lyxerr << " paintRows: row: " << &*row << " ignored" << endl;
1079 int paintText(BufferView & bv)
1081 int const topy = bv.top_y();
1082 ParagraphList::iterator pit;
1083 RowList::iterator rit = bv.text->getRowNearY(topy, pit);
1084 int y = rit->y() - topy;
1085 return paintRows(bv, *bv.text, pit, rit, 0, y, y, 0);
1089 void paintTextInset(BufferView & bv, LyXText & text, int x, int baseline)
1091 RowList::iterator rit = text.firstRow();
1092 RowList::iterator end = text.endRow();
1093 ParagraphList::iterator pit = text.ownerParagraphs().begin();
1095 int y_offset = baseline - rit->ascent_of_text();
1097 while (rit != end && y + rit->height() <= 0) {
1099 text.nextRow(pit, rit);
1102 paintRows(bv, text, pit, rit, x, 0, y, y);
1104 paintRows(bv, text, pit, rit, x, 0, y_offset, y_offset);
1108 int getLengthMarkerHeight(BufferView const & bv, VSpace const & vsp)
1110 if (vsp.kind() == VSpace::NONE)
1113 int const arrow_size = 4;
1114 int const space_size = vsp.inPixels(bv);
1118 int const min_size = max(3 * arrow_size,
1119 font_metrics::maxAscent(font)
1120 + font_metrics::maxDescent(font));
1122 if (vsp.length().len().value() < 0.0)
1125 return max(min_size, space_size);