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/font_metrics.h"
16 #include "support/LAssert.h"
17 #include "paragraph_funcs.h"
18 #include "support/textutils.h"
20 #include "insets/insettext.h"
21 #include "ParagraphParameters.h"
22 #include "BufferView.h"
27 #include "rowpainter.h"
28 #include "lyxrow_funcs.h"
29 #include "metricsinfo.h"
33 using namespace lyx::support;
39 extern int PAPER_MARGIN;
40 extern int CHANGEBAR_MARGIN;
41 extern int LEFT_MARGIN;
45 // "temporary". We'll never get to use more
46 // references until we start adding hacks like
47 // these until other places catch up.
48 BufferView * perv(BufferView const & bv)
50 return const_cast<BufferView *>(&bv);
54 * A class used for painting an individual row of text.
58 /// initialise painter
59 RowPainter(BufferView const & bv, LyXText const & text,
60 ParagraphList::iterator pit,
61 RowList::iterator rit, int y_offset, int x_offset, int y);
66 // paint various parts
67 void paintBackground();
68 void paintSelection();
71 void paintChangeBar();
74 void paintForeignMark(double orig_x, LyXFont const & orig_font);
75 void paintHebrewComposeChar(lyx::pos_type & vpos);
76 void paintArabicComposeChar(lyx::pos_type & vpos);
77 void paintChars(lyx::pos_type & vpos, bool hebrew, bool arabic);
78 int paintPageBreak(string const & label, int y);
79 int paintAppendixStart(int y);
80 int paintLengthMarker(string const & prefix, VSpace const & vsp, int start);
82 void paintFromPos(lyx::pos_type & vpos);
83 void paintInset(lyx::pos_type const pos);
85 /// return left margin
86 int leftMargin() const;
88 /// return the font at the given pos
89 LyXFont const getFont(lyx::pos_type pos) const;
91 /// return the label font for this row
92 LyXFont const getLabelFont() const;
94 char const transformChar(char c, lyx::pos_type pos) const;
96 /// return pixel width for the given pos
97 int singleWidth(lyx::pos_type pos) const;
98 int singleWidth(lyx::pos_type pos, char c) const;
100 /// bufferview to paint on
101 BufferView const & bv_;
106 /// LyXText for the row
107 LyXText const & text_;
110 RowList::iterator row_;
113 mutable ParagraphList::iterator pit_;
127 RowPainter::RowPainter(BufferView const & bv, LyXText const & text,
128 ParagraphList::iterator pit, RowList::iterator rit,
129 int y_offset, int x_offset, int y)
130 : bv_(bv), pain_(bv_.painter()), text_(text), row_(rit),
131 pit_(pit), xo_(x_offset), yo_(y_offset), y_(y)
136 LyXFont const RowPainter::getFont(pos_type pos) const
138 return text_.getFont(pit_, pos);
142 int RowPainter::singleWidth(lyx::pos_type pos) const
144 return text_.singleWidth(pit_, pos);
148 int RowPainter::singleWidth(lyx::pos_type pos, char c) const
150 LyXFont const & font = text_.getFont(pit_, pos);
151 return text_.singleWidth(pit_, pos, c, font);
155 LyXFont const RowPainter::getLabelFont() const
157 return text_.getLabelFont(pit_);
161 char const RowPainter::transformChar(char c, lyx::pos_type pos) const
163 return text_.transformChar(c, *pit_, pos);
167 int RowPainter::leftMargin() const
169 return text_.leftMargin(pit_, *row_);
173 void RowPainter::paintInset(pos_type const pos)
175 InsetOld * inset = const_cast<InsetOld*>(pit_->getInset(pos));
179 PainterInfo pi(perv(bv_));
180 pi.base.font = getFont(pos);
181 inset->draw(pi, int(x_), yo_ + row_->baseline());
182 x_ += inset->width();
186 void RowPainter::paintHebrewComposeChar(pos_type & vpos)
188 pos_type pos = text_.vis2log(vpos);
193 char c = pit_->getChar(pos);
197 LyXFont const & font = getFont(pos);
198 int const width = font_metrics::width(c, font);
201 for (pos_type i = pos - 1; i >= 0; --i) {
202 c = pit_->getChar(i);
203 if (!Encodings::IsComposeChar_hebrew(c)) {
204 if (IsPrintableNonspace(c)) {
208 dx = (c == 'ø' || c == 'ã')
210 : (width2 - width) / 2;
217 pain_.text(int(x_) + dx, yo_ + row_->baseline(), str, font);
221 void RowPainter::paintArabicComposeChar(pos_type & vpos)
223 pos_type pos = text_.vis2log(vpos);
227 char c = pit_->getChar(pos);
228 c = transformChar(c, pos);
232 LyXFont const & font = getFont(pos);
233 int const width = font_metrics::width(c, font);
236 for (pos_type i = pos - 1; i >= 0; --i) {
237 c = pit_->getChar(i);
238 if (!Encodings::IsComposeChar_arabic(c)) {
239 if (IsPrintableNonspace(c)) {
242 dx = (width2 - width) / 2;
248 pain_.text(int(x_) + dx, yo_ + row_->baseline(), str, font);
252 void RowPainter::paintChars(pos_type & vpos, bool hebrew, bool arabic)
254 pos_type pos = text_.vis2log(vpos);
255 pos_type const last = lastPos(*pit_, row_);
256 LyXFont orig_font = getFont(pos);
260 str += pit_->getChar(pos);
262 unsigned char c = str[0];
263 str[0] = transformChar(c, pos);
266 bool prev_struckout(isDeletedText(*pit_, pos));
267 bool prev_newtext(isInsertedText(*pit_, pos));
271 // collect as much similar chars as we can
272 while (vpos <= last && (pos = text_.vis2log(vpos)) >= 0) {
273 char c = pit_->getChar(pos);
275 if (!IsPrintableNonspace(c))
278 if (prev_struckout != isDeletedText(*pit_, pos))
281 if (prev_newtext != isInsertedText(*pit_, pos))
284 if (arabic && Encodings::IsComposeChar_arabic(c))
286 if (hebrew && Encodings::IsComposeChar_hebrew(c))
289 if (orig_font != getFont(pos))
293 c = transformChar(c, pos);
298 if (prev_struckout) {
299 orig_font.setColor(LColor::strikeout);
300 } else if (prev_newtext) {
301 orig_font.setColor(LColor::newtext);
304 // Draw text and set the new x position
305 //lyxerr << "paint row: yo_ " << yo_ << " baseline: " << row_->baseline()
307 pain_.text(int(x_), yo_ + row_->baseline(), str, orig_font);
308 x_ += font_metrics::width(str, orig_font);
312 void RowPainter::paintForeignMark(double orig_x, LyXFont const & orig_font)
314 if (!lyxrc.mark_foreign_language)
316 if (orig_font.language() == latex_language)
318 if (orig_font.language() == bv_.buffer()->params.language)
321 int const y = yo_ + row_->baseline() + 1;
322 pain_.line(int(orig_x), y, int(x_), y, LColor::language);
326 void RowPainter::paintFromPos(pos_type & vpos)
328 pos_type const pos = text_.vis2log(vpos);
330 LyXFont const & orig_font = getFont(pos);
332 double const orig_x = x_;
334 char const c = pit_->getChar(pos);
336 if (IsInsetChar(c)) {
339 paintForeignMark(orig_x, orig_font);
343 // usual characters, no insets
345 // special case languages
346 bool const hebrew = (orig_font.language()->lang() == "hebrew");
348 orig_font.language()->lang() == "arabic" &&
349 (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
350 lyxrc.font_norm_type == LyXRC::ISO_10646_1);
352 // draw as many chars as we can
353 if ((!hebrew && !arabic)
354 || (hebrew && !Encodings::IsComposeChar_hebrew(c))
355 || (arabic && !Encodings::IsComposeChar_arabic(c))) {
356 paintChars(vpos, hebrew, arabic);
358 paintHebrewComposeChar(vpos);
360 paintArabicComposeChar(vpos);
363 paintForeignMark(orig_x, orig_font);
369 void RowPainter::paintBackground()
371 int const x = int(xo_);
372 int const y = yo_ < 0 ? 0 : yo_;
373 int const h = yo_ < 0 ? row_->height() + yo_ : row_->height();
374 pain_.fillRectangle(x, y, width_, h, text_.backgroundColor());
378 void RowPainter::paintSelection()
380 bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params);
382 // the current selection
383 int const startx = text_.selection.start.x();
384 int const endx = text_.selection.end.x();
385 int const starty = text_.selection.start.y();
386 int const endy = text_.selection.end.y();
387 RowList::iterator startrow = text_.getRow(text_.selection.start);
388 RowList::iterator endrow = text_.getRow(text_.selection.end);
390 if (text_.bidi_same_direction) {
394 int h = row_->height();
396 if (startrow == row_ && endrow == row_) {
398 x = int(xo_) + startx;
400 pain_.fillRectangle(x, y, w, h, LColor::selection);
404 pain_.fillRectangle(x, y, w, h, LColor::selection);
406 } else if (startrow == row_) {
407 int const x = is_rtl ? int(xo_) : int(xo_ + startx);
408 int const w = is_rtl ? startx : (width_ - startx);
409 pain_.fillRectangle(x, y, w, h, LColor::selection);
410 } else if (endrow == row_) {
411 int const x = is_rtl ? int(xo_ + endx) : int(xo_);
412 int const w = is_rtl ? (width_ - endx) : endx;
413 pain_.fillRectangle(x, y, w, h, LColor::selection);
414 } else if (y_ > starty && y_ < endy) {
415 pain_.fillRectangle(int(xo_), y, width_, h, LColor::selection);
418 } else if (startrow != row_ && endrow != row_) {
419 if (y_ > starty && y_ < endy) {
421 int h = row_->height();
422 pain_.fillRectangle(int(xo_), yo_, w, h, LColor::selection);
427 if ((startrow != row_ && !is_rtl) || (endrow != row_ && is_rtl))
428 pain_.fillRectangle(int(xo_), yo_,
429 int(x_), row_->height(), LColor::selection);
431 pos_type const body_pos = pit_->beginningOfBody();
432 pos_type const last = lastPos(*pit_, row_);
435 for (pos_type vpos = row_->pos(); vpos <= last; ++vpos) {
436 pos_type pos = text_.vis2log(vpos);
437 double 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(*pit_, 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(int(xo_ + 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 = lastPos(*pit_, row_);
486 if (!pit_->isChanged(start, end))
489 int const height = (row_ == text_.lastRow())
491 : 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_.firstRow()) {
524 ParagraphList::iterator pit2 = pit_;
525 if (row_ == pit2->rows.begin())
527 prev_depth = pit2->getDepth();
530 Paragraph::depth_type next_depth = 0;
531 if (row_ != text_.lastRow()) {
532 ParagraphList::iterator pit2 = pit_;
533 if (boost::next(row_) == pit2->rows.end())
535 next_depth = pit2->getDepth();
538 for (Paragraph::depth_type i = 1; i <= depth; ++i) {
539 int const w = PAPER_MARGIN / 5;
540 int x = int(w * i + xo_);
541 // only consider the changebar space if we're drawing outer left
543 x += CHANGEBAR_MARGIN;
544 int const h = yo_ + row_->height() - 1 - (i - next_depth - 1) * 3;
546 pain_.line(x, yo_, x, h, LColor::depthbar);
549 pain_.fillRectangle(x, yo_, w, 2, LColor::depthbar);
551 pain_.fillRectangle(x, h, w, 2, LColor::depthbar);
556 int RowPainter::paintLengthMarker(string const & prefix, VSpace const & vsp, int start)
558 if (vsp.kind() == VSpace::NONE)
561 int const arrow_size = 4;
562 int const size = getLengthMarkerHeight(bv_, vsp);
563 int const end = start + size;
565 // the label to display (if any)
567 // y-values for top arrow
569 // y-values for bottom arrow
572 str = prefix + " (" + vsp.asLyXCommand() + ")";
574 if (vsp.kind() == VSpace::VFILL) {
578 // adding or removing space
579 bool const added = vsp.kind() != VSpace::LENGTH ||
580 vsp.length().len().value() > 0.0;
581 ty1 = added ? (start + arrow_size) : start;
582 ty2 = added ? start : (start + arrow_size);
583 by1 = added ? (end - arrow_size) : end;
584 by2 = added ? end : (end - arrow_size);
587 int const leftx = int(xo_) + leftMargin();
588 int const midx = leftx + arrow_size;
589 int const rightx = midx + arrow_size;
597 font.setColor(LColor::added_space).decSize().decSize();
598 font_metrics::rectText(str, font, w, a, d);
600 pain_.rectText(leftx + 2 * arrow_size + 5,
601 start + ((end - start) / 2) + d,
605 pain_.line(leftx, ty1, midx, ty2, LColor::added_space);
606 pain_.line(midx, ty2, rightx, ty1, LColor::added_space);
609 pain_.line(leftx, by1, midx, by2, LColor::added_space);
610 pain_.line(midx, by2, rightx, by1, LColor::added_space);
613 pain_.line(midx, ty2, midx, by2, LColor::added_space);
619 int RowPainter::paintPageBreak(string const & label, int y)
622 pb_font.setColor(LColor::pagebreak).decSize();
627 font_metrics::rectText(label, pb_font, w, a, d);
629 int const text_start = int(xo_ + (width_ - w) / 2);
630 int const text_end = text_start + w;
632 pain_.rectText(text_start, y + d, label, pb_font);
634 pain_.line(int(xo_), y, text_start, y,
635 LColor::pagebreak, Painter::line_onoffdash);
636 pain_.line(text_end, y, int(xo_ + width_), y,
637 LColor::pagebreak, Painter::line_onoffdash);
639 return 3 * defaultRowHeight();
643 int RowPainter::paintAppendixStart(int y)
646 pb_font.setColor(LColor::appendix).decSize();
648 string const label = _("Appendix");
652 font_metrics::rectText(label, pb_font, w, a, d);
654 int const text_start = int(xo_ + (width_ - w) / 2);
655 int const text_end = text_start + w;
657 pain_.rectText(text_start, y + d, label, pb_font);
659 pain_.line(int(xo_ + 1), y, text_start, y, LColor::appendix);
660 pain_.line(text_end, y, int(xo_ + width_ - 2), y, LColor::appendix);
662 return 3 * defaultRowHeight();
666 void RowPainter::paintFirst()
668 ParagraphParameters const & parparams = pit_->params();
672 // start of appendix?
673 if (parparams.startOfAppendix())
674 y_top += paintAppendixStart(yo_ + y_top + 2 * defaultRowHeight());
677 if (row_ == text_.firstRow() && !text_.isInInset())
678 y_top += PAPER_MARGIN;
680 // draw a top pagebreak
681 if (parparams.pagebreakTop())
682 y_top += paintPageBreak(_("Page Break (top)"),
683 yo_ + y_top + 2 * defaultRowHeight());
685 // draw the additional space if needed:
686 y_top += paintLengthMarker(_("Space above"), parparams.spaceTop(),
689 Buffer const & buffer = *bv_.buffer();
691 LyXLayout_ptr const & layout = pit_->layout();
693 if (buffer.params.paragraph_separation == BufferParams::PARSEP_SKIP) {
694 if (pit_ != text_.ownerParagraphs().begin()) {
695 if (layout->latextype == LATEX_PARAGRAPH
696 && !pit_->getDepth()) {
697 y_top += buffer.params.getDefSkip().inPixels(bv_);
699 LyXLayout_ptr const & playout =
700 boost::prior(pit_)->layout();
701 if (playout->latextype == LATEX_PARAGRAPH
702 && !boost::prior(pit_)->getDepth()) {
703 // is it right to use defskip here, too? (AS)
704 y_top += buffer.params.getDefSkip().inPixels(bv_);
710 int const ww = bv_.workWidth();
713 if (parparams.lineTop()) {
714 int const asc = font_metrics::ascent('x', getFont(0));
718 int const w = (text_.isInInset() ? text_.inset_owner->width() : ww);
719 int const xp = static_cast<int>(text_.isInInset() ? xo_ : 0);
720 pain_.line(xp, yo_ + y_top, xp + w, yo_ + y_top,
721 LColor::topline, Painter::line_solid,
722 Painter::line_thick);
727 bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params);
729 // should we print a label?
730 if (layout->labeltype >= LABEL_STATIC
731 && (layout->labeltype != LABEL_STATIC
732 || layout->latextype != LATEX_ENVIRONMENT
733 || isFirstInSequence(pit_, text_.ownerParagraphs()))) {
735 LyXFont font = getLabelFont();
736 if (!pit_->getLabelstring().empty()) {
738 string const str = pit_->getLabelstring();
740 // this is special code for the chapter layout. This is
741 // printed in an extra row and has a pagebreak at
743 if (layout->labeltype == LABEL_COUNTER_CHAPTER) {
744 if (buffer.params.secnumdepth >= 0) {
745 float spacing_val = 1.0;
746 if (!parparams.spacing().isDefault()) {
747 spacing_val = parparams.spacing().getValue();
749 spacing_val = buffer.params.spacing.getValue();
753 int(font_metrics::maxDescent(font) * layout->spacing.getValue() * spacing_val)
754 + int(layout->parsep) * defaultRowHeight();
757 x = ww - leftMargin() -
758 font_metrics::width(str, font);
762 yo_ + row_->baseline() -
763 row_->ascent_of_text() - maxdesc,
768 x = ww - leftMargin()
769 + font_metrics::width(layout->labelsep, font);
771 x = x_ - font_metrics::width(layout->labelsep, font)
772 - font_metrics::width(str, font);
775 pain_.text(int(x), yo_ + row_->baseline(), str, font);
779 // the labels at the top of an environment.
780 // More or less for bibliography
781 } else if (isFirstInSequence(pit_, text_.ownerParagraphs()) &&
782 (layout->labeltype == LABEL_TOP_ENVIRONMENT ||
783 layout->labeltype == LABEL_BIBLIO ||
784 layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)) {
785 LyXFont font = getLabelFont();
786 if (!pit_->getLabelstring().empty()) {
787 string const str = pit_->getLabelstring();
788 float spacing_val = 1.0;
789 if (!parparams.spacing().isDefault()) {
790 spacing_val = parparams.spacing().getValue();
792 spacing_val = buffer.params.spacing.getValue();
796 int(font_metrics::maxDescent(font) * layout->spacing.getValue() * spacing_val
797 + (layout->labelbottomsep * defaultRowHeight()));
800 if (layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
801 x = ((is_rtl ? leftMargin() : x_)
802 + ww - text_.rightMargin(pit_, *bv_.buffer(), *row_)) / 2;
803 x -= font_metrics::width(str, font) / 2;
805 x = ww - leftMargin() -
806 font_metrics::width(str, font);
809 yo_ + row_->baseline() - row_->ascent_of_text() - maxdesc,
816 void RowPainter::paintLast()
818 ParagraphParameters const & parparams = pit_->params();
819 int y_bottom = row_->height() - 1;
822 if (row_ == text_.lastRow() && !text_.isInInset())
823 y_bottom -= PAPER_MARGIN;
825 int const ww = bv_.workWidth();
827 // draw a bottom pagebreak
828 if (parparams.pagebreakBottom()) {
829 y_bottom -= paintPageBreak(_("Page Break (bottom)"),
830 yo_ + y_bottom - 2 * defaultRowHeight());
833 // draw the additional space if needed:
834 int const height = getLengthMarkerHeight(bv_, parparams.spaceBottom());
835 y_bottom -= paintLengthMarker(_("Space below"), parparams.spaceBottom(),
836 yo_ + y_bottom - height);
838 // draw a bottom line
839 if (parparams.lineBottom()) {
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() : ww;
846 int const xp = 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);
876 case END_LABEL_STATIC:
878 LyXFont font = getLabelFont();
879 string const & str = pit_->layout()->endlabelstring();
880 double const x = is_rtl ?
881 x_ - font_metrics::width(str, font)
882 : ww - text_.rightMargin(pit_, *bv_.buffer(), *row_) - row_->fill();
883 pain_.text(int(x), yo_ + row_->baseline(), str, font);
886 case END_LABEL_NO_LABEL:
892 void RowPainter::paintText()
894 pos_type const last = lastPos(*pit_, row_);
895 pos_type body_pos = pit_->beginningOfBody();
897 (body_pos - 1 > last || !pit_->isLineSeparator(body_pos - 1))) {
901 LyXLayout_ptr const & layout = pit_->layout();
903 bool running_strikeout = false;
904 bool is_struckout = false;
905 int last_strikeout_x = 0;
907 pos_type vpos = row_->pos();
908 while (vpos <= last) {
909 if (x_ > bv_.workWidth())
911 pos_type pos = text_.vis2log(vpos);
913 if (pos >= pit_->size()) {
918 if (x_ + singleWidth(pos) < 0) {
919 x_ += singleWidth(pos);
924 is_struckout = isDeletedText(*pit_, pos);
926 if (is_struckout && !running_strikeout) {
927 running_strikeout = true;
928 last_strikeout_x = int(x_);
931 bool const highly_editable_inset = pit_->isInset(pos)
932 && isHighlyEditableInset(pit_->getInset(pos));
934 // if we reach the end of a struck out range, paint it
935 // we also don't paint across things like tables
936 if (running_strikeout && (highly_editable_inset || !is_struckout)) {
937 int const middle = yo_ + row_->top_of_text()
938 + (row_->baseline() - row_->top_of_text()) / 2;
939 pain_.line(last_strikeout_x, middle, int(x_), middle,
940 LColor::strikeout, Painter::line_solid, Painter::line_thin);
941 running_strikeout = false;
944 if (body_pos > 0 && pos == body_pos - 1) {
945 int const lwidth = font_metrics::width(layout->labelsep,
948 x_ += label_hfill_ + lwidth - singleWidth(body_pos - 1);
951 if (pit_->isHfill(pos)) {
954 int const y0 = yo_ + row_->baseline();
955 int const y1 = y0 - defaultRowHeight() / 2;
957 pain_.line(int(x_), y1, int(x_), y0, LColor::added_space);
959 if (hfillExpansion(*pit_, row_, pos)) {
960 int const y2 = (y0 + y1) / 2;
962 if (pos >= body_pos) {
963 pain_.line(int(x_), y2, int(x_ + hfill_), y2,
965 Painter::line_onoffdash);
968 pain_.line(int(x_), y2, int(x_ + label_hfill_), y2,
970 Painter::line_onoffdash);
973 pain_.line(int(x_), y1, int(x_), y0, LColor::added_space);
977 } else if (pit_->isSeparator(pos)) {
978 x_ += singleWidth(pos);
987 // if we reach the end of a struck out range, paint it
988 if (running_strikeout) {
989 int const middle = yo_ + row_->top_of_text()
990 + ((row_->baseline() - row_->top_of_text()) / 2);
991 pain_.line(last_strikeout_x, middle, int(x_), middle,
992 LColor::strikeout, Painter::line_solid, Painter::line_thin);
993 running_strikeout = false;
998 void RowPainter::paint()
1000 width_ = text_.workWidth();
1002 separator_ = row_->fill_separator();
1003 hfill_ = row_->fill_hfill();
1004 label_hfill_ = row_->fill_label_hfill();
1006 // FIXME: what is this fixing ?
1007 if (text_.isInInset() && x_ < 0)
1011 // If we're *not* at the top-level of rows, then the
1012 // background has already been cleared.
1013 if (&text_ == bv_.text)
1016 // paint the selection background
1017 if (text_.selection.set())
1020 // vertical lines for appendix
1023 // environment depth brackets
1029 if (row_->isParStart())
1032 if (isParEnd(*pit_, row_))
1040 int paintRows(BufferView const & bv, LyXText const & text,
1041 ParagraphList::iterator pit, RowList::iterator rit,
1042 int xo, int y, int yf, int yo)
1044 //lyxerr << " paintRows: rit: " << &*rit << endl;
1045 //const_cast<LyXText&>(text).updateRowPositions();
1046 int const yy = yf - y;
1047 int const y2 = bv.painter().paperHeight();
1049 ParagraphList::iterator end = text.ownerParagraphs().end();
1050 bool active = false;
1052 for ( ; pit != end; ++pit) {
1053 RowList::iterator row = pit->rows.begin();
1054 RowList::iterator rend = pit->rows.end();
1056 for ( ; row != rend; ++row) {
1060 RowPainter painter(bv, text, pit, row, y + yo, xo, y + bv.top_y());
1066 //lyxerr << " paintRows: row: " << &*row << " ignored" << endl;
1077 int paintText(BufferView & bv)
1079 int const topy = bv.top_y();
1080 ParagraphList::iterator pit;
1081 RowList::iterator rit = bv.text->getRowNearY(topy, pit);
1082 int y = rit->y() - topy;
1083 return paintRows(bv, *bv.text, pit, rit, 0, y, y, 0);
1087 void paintTextInset(BufferView & bv, LyXText & text, int x, int baseline)
1089 RowList::iterator rit = text.firstRow();
1090 RowList::iterator end = text.endRow();
1091 ParagraphList::iterator pit = text.ownerParagraphs().begin();
1093 int y_offset = baseline - rit->ascent_of_text();
1095 while (rit != end && y + rit->height() <= 0) {
1097 text.nextRow(pit, rit);
1100 paintRows(bv, text, pit, rit, x, 0, y, y);
1102 paintRows(bv, text, pit, rit, x, 0, y_offset, y_offset);
1106 int getLengthMarkerHeight(BufferView const & bv, VSpace const & vsp)
1108 if (vsp.kind() == VSpace::NONE)
1111 int const arrow_size = 4;
1112 int const space_size = vsp.inPixels(bv);
1116 int const min_size = max(3 * arrow_size,
1117 font_metrics::maxAscent(font)
1118 + font_metrics::maxDescent(font));
1120 if (vsp.length().len().value() < 0.0)
1123 return max(min_size, space_size);