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"
32 using namespace lyx::support;
38 extern int PAPER_MARGIN;
39 extern int CHANGEBAR_MARGIN;
40 extern int LEFT_MARGIN;
44 // "temporary". We'll never get to use more
45 // references until we start adding hacks like
46 // these until other places catch up.
47 BufferView * perv(BufferView const & bv)
49 return const_cast<BufferView *>(&bv);
53 * A class used for painting an individual row of text.
57 /// initialise painter
58 RowPainter(BufferView const & bv, LyXText const & text,
59 ParagraphList::iterator pit,
60 RowList::iterator rit, int y_offset, int x_offset, int y);
65 // paint various parts
66 void paintBackground();
67 void paintSelection();
70 void paintChangeBar();
73 void paintForeignMark(double orig_x, LyXFont const & orig_font);
74 void paintHebrewComposeChar(lyx::pos_type & vpos);
75 void paintArabicComposeChar(lyx::pos_type & vpos);
76 void paintChars(lyx::pos_type & vpos, bool hebrew, bool arabic);
77 int paintPageBreak(string const & label, int y);
78 int paintAppendixStart(int y);
79 int paintLengthMarker(string const & prefix, VSpace const & vsp, int start);
81 void paintFromPos(lyx::pos_type & vpos);
82 void paintInset(lyx::pos_type const pos);
84 /// return left margin
85 int leftMargin() const;
87 /// return the font at the given pos
88 LyXFont const getFont(lyx::pos_type pos) const;
90 /// return the label font for this row
91 LyXFont const getLabelFont() const;
93 char const transformChar(char c, lyx::pos_type pos) const;
95 /// return pixel width for the given pos
96 int singleWidth(lyx::pos_type pos) const;
97 int singleWidth(lyx::pos_type pos, char c) const;
99 /// bufferview to paint on
100 BufferView const & bv_;
105 /// LyXText for the row
106 LyXText const & text_;
109 RowList::iterator row_;
112 mutable ParagraphList::iterator pit_;
126 RowPainter::RowPainter(BufferView const & bv, LyXText const & text,
127 ParagraphList::iterator pit, RowList::iterator rit,
128 int y_offset, int x_offset, int y)
129 : bv_(bv), pain_(bv_.painter()), text_(text), row_(rit),
130 pit_(pit), xo_(x_offset), yo_(y_offset), y_(y)
135 LyXFont const RowPainter::getFont(pos_type pos) const
137 return text_.getFont(pit_, pos);
141 int RowPainter::singleWidth(lyx::pos_type pos) const
143 return text_.singleWidth(pit_, pos);
147 int RowPainter::singleWidth(lyx::pos_type pos, char c) const
149 LyXFont const & font = text_.getFont(pit_, pos);
150 return text_.singleWidth(pit_, pos, c, font);
154 LyXFont const RowPainter::getLabelFont() const
156 return text_.getLabelFont(pit_);
160 char const RowPainter::transformChar(char c, lyx::pos_type pos) const
162 return text_.transformChar(c, *pit_, pos);
166 int RowPainter::leftMargin() const
168 return text_.leftMargin(pit_, *row_);
172 void RowPainter::paintInset(pos_type const pos)
174 InsetOld * inset = const_cast<InsetOld*>(pit_->getInset(pos));
178 PainterInfo pi(perv(bv_));
179 pi.base.font = getFont(pos);
180 inset->draw(pi, int(x_), yo_ + row_->baseline());
181 x_ += inset->width();
185 void RowPainter::paintHebrewComposeChar(pos_type & vpos)
187 pos_type pos = text_.vis2log(vpos);
192 char c = pit_->getChar(pos);
196 LyXFont const & font = getFont(pos);
197 int const width = font_metrics::width(c, font);
200 for (pos_type i = pos - 1; i >= 0; --i) {
201 c = pit_->getChar(i);
202 if (!Encodings::IsComposeChar_hebrew(c)) {
203 if (IsPrintableNonspace(c)) {
207 dx = (c == 'ø' || c == 'ã')
209 : (width2 - width) / 2;
216 pain_.text(int(x_) + dx, yo_ + row_->baseline(), str, font);
220 void RowPainter::paintArabicComposeChar(pos_type & vpos)
222 pos_type pos = text_.vis2log(vpos);
226 char c = pit_->getChar(pos);
227 c = transformChar(c, pos);
231 LyXFont const & font = getFont(pos);
232 int const width = font_metrics::width(c, font);
235 for (pos_type i = pos - 1; i >= 0; --i) {
236 c = pit_->getChar(i);
237 if (!Encodings::IsComposeChar_arabic(c)) {
238 if (IsPrintableNonspace(c)) {
241 dx = (width2 - width) / 2;
247 pain_.text(int(x_) + dx, yo_ + row_->baseline(), str, font);
251 void RowPainter::paintChars(pos_type & vpos, bool hebrew, bool arabic)
253 pos_type pos = text_.vis2log(vpos);
254 pos_type const last = lastPos(*pit_, row_);
255 LyXFont orig_font = getFont(pos);
259 str += pit_->getChar(pos);
261 unsigned char c = str[0];
262 str[0] = transformChar(c, pos);
265 bool prev_struckout(isDeletedText(*pit_, pos));
266 bool prev_newtext(isInsertedText(*pit_, pos));
270 // collect as much similar chars as we can
271 while (vpos <= last && (pos = text_.vis2log(vpos)) >= 0) {
272 char c = pit_->getChar(pos);
274 if (!IsPrintableNonspace(c))
277 if (prev_struckout != isDeletedText(*pit_, pos))
280 if (prev_newtext != isInsertedText(*pit_, pos))
283 if (arabic && Encodings::IsComposeChar_arabic(c))
285 if (hebrew && Encodings::IsComposeChar_hebrew(c))
288 if (orig_font != getFont(pos))
292 c = transformChar(c, pos);
297 if (prev_struckout) {
298 orig_font.setColor(LColor::strikeout);
299 } else if (prev_newtext) {
300 orig_font.setColor(LColor::newtext);
303 // Draw text and set the new x position
304 //lyxerr << "paint row: yo_ " << yo_ << " baseline: " << row_->baseline()
306 pain_.text(int(x_), yo_ + row_->baseline(), str, orig_font);
307 x_ += font_metrics::width(str, orig_font);
311 void RowPainter::paintForeignMark(double orig_x, LyXFont const & orig_font)
313 if (!lyxrc.mark_foreign_language)
315 if (orig_font.language() == latex_language)
317 if (orig_font.language() == bv_.buffer()->params.language)
320 int const y = yo_ + row_->baseline() + 1;
321 pain_.line(int(orig_x), y, int(x_), y, LColor::language);
325 void RowPainter::paintFromPos(pos_type & vpos)
327 pos_type const pos = text_.vis2log(vpos);
329 LyXFont const & orig_font = getFont(pos);
331 double const orig_x = x_;
333 char const c = pit_->getChar(pos);
335 if (IsInsetChar(c)) {
338 paintForeignMark(orig_x, orig_font);
342 // usual characters, no insets
344 // special case languages
345 bool const hebrew = (orig_font.language()->lang() == "hebrew");
347 orig_font.language()->lang() == "arabic" &&
348 (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
349 lyxrc.font_norm_type == LyXRC::ISO_10646_1);
351 // draw as many chars as we can
352 if ((!hebrew && !arabic)
353 || (hebrew && !Encodings::IsComposeChar_hebrew(c))
354 || (arabic && !Encodings::IsComposeChar_arabic(c))) {
355 paintChars(vpos, hebrew, arabic);
357 paintHebrewComposeChar(vpos);
359 paintArabicComposeChar(vpos);
362 paintForeignMark(orig_x, orig_font);
368 void RowPainter::paintBackground()
370 int const x = int(xo_);
371 int const y = yo_ < 0 ? 0 : yo_;
372 int const h = yo_ < 0 ? row_->height() + yo_ : row_->height();
373 pain_.fillRectangle(x, y, width_, h, text_.backgroundColor());
377 void RowPainter::paintSelection()
379 bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params);
381 // the current selection
382 int const startx = text_.selection.start.x();
383 int const endx = text_.selection.end.x();
384 int const starty = text_.selection.start.y();
385 int const endy = text_.selection.end.y();
386 RowList::iterator startrow = text_.getRow(text_.selection.start);
387 RowList::iterator endrow = text_.getRow(text_.selection.end);
389 if (text_.bidi_same_direction) {
393 int h = row_->height();
395 if (startrow == row_ && endrow == row_) {
397 x = int(xo_) + startx;
399 pain_.fillRectangle(x, y, w, h, LColor::selection);
403 pain_.fillRectangle(x, y, w, h, LColor::selection);
405 } else if (startrow == row_) {
406 int const x = is_rtl ? int(xo_) : int(xo_ + startx);
407 int const w = is_rtl ? startx : (width_ - startx);
408 pain_.fillRectangle(x, y, w, h, LColor::selection);
409 } else if (endrow == row_) {
410 int const x = is_rtl ? int(xo_ + endx) : int(xo_);
411 int const w = is_rtl ? (width_ - endx) : endx;
412 pain_.fillRectangle(x, y, w, h, LColor::selection);
413 } else if (y_ > starty && y_ < endy) {
414 pain_.fillRectangle(int(xo_), y, width_, h, LColor::selection);
417 } else if (startrow != row_ && endrow != row_) {
418 if (y_ > starty && y_ < endy) {
420 int h = row_->height();
421 pain_.fillRectangle(int(xo_), yo_, w, h, LColor::selection);
426 if ((startrow != row_ && !is_rtl) || (endrow != row_ && is_rtl))
427 pain_.fillRectangle(int(xo_), yo_,
428 int(x_), row_->height(), LColor::selection);
430 pos_type const body_pos = pit_->beginningOfBody();
431 pos_type const last = lastPos(*pit_, row_);
434 for (pos_type vpos = row_->pos(); vpos <= last; ++vpos) {
435 pos_type pos = text_.vis2log(vpos);
436 double const old_tmpx = tmpx;
437 if (body_pos > 0 && pos == body_pos - 1) {
438 LyXLayout_ptr const & layout = pit_->layout();
439 LyXFont const lfont = getLabelFont();
441 tmpx += label_hfill_ + font_metrics::width(layout->labelsep, lfont);
443 if (pit_->isLineSeparator(body_pos - 1))
444 tmpx -= singleWidth(body_pos - 1);
447 if (hfillExpansion(*pit_, row_, pos)) {
448 tmpx += singleWidth(pos);
452 tmpx += label_hfill_;
455 else if (pit_->isSeparator(pos)) {
456 tmpx += singleWidth(pos);
460 tmpx += singleWidth(pos);
463 if ((startrow != row_ || text_.selection.start.pos() <= pos) &&
464 (endrow != row_ || pos < text_.selection.end.pos())) {
465 // Here we do not use x_ as xo_ was added to x_.
466 pain_.fillRectangle(int(old_tmpx), yo_,
467 int(tmpx - old_tmpx + 1),
468 row_->height(), LColor::selection);
472 if ((startrow != row_ && is_rtl) || (endrow != row_ && !is_rtl)) {
473 pain_.fillRectangle(int(xo_ + tmpx),
474 yo_, int(bv_.workWidth() - tmpx),
475 row_->height(), LColor::selection);
480 void RowPainter::paintChangeBar()
482 pos_type const start = row_->pos();
483 pos_type const end = lastPos(*pit_, row_);
485 if (!pit_->isChanged(start, end))
488 int const height = (row_ == text_.lastRow())
490 : row_->height() + boost::next(row_)->top_of_text();
492 pain_.fillRectangle(4, yo_, 5, height, LColor::changebar);
496 void RowPainter::paintAppendix()
498 if (!pit_->params().appendix())
501 // FIXME: can be just width_ ?
502 int const ww = bv_.workWidth();
506 if (pit_->params().startOfAppendix())
507 y += 2 * defaultRowHeight();
509 pain_.line(1, y, 1, yo_ + row_->height(), LColor::appendix);
510 pain_.line(ww - 2, y, ww - 2, yo_ + row_->height(), LColor::appendix);
514 void RowPainter::paintDepthBar()
516 Paragraph::depth_type const depth = pit_->getDepth();
521 Paragraph::depth_type prev_depth = 0;
522 if (row_ != text_.firstRow()) {
523 ParagraphList::iterator pit2 = pit_;
524 if (row_ == pit2->rows.begin())
526 prev_depth = pit2->getDepth();
529 Paragraph::depth_type next_depth = 0;
530 if (row_ != text_.lastRow()) {
531 ParagraphList::iterator pit2 = pit_;
532 if (boost::next(row_) == pit2->rows.end())
534 next_depth = pit2->getDepth();
537 for (Paragraph::depth_type i = 1; i <= depth; ++i) {
538 int const w = PAPER_MARGIN / 5;
539 int x = int(w * i + xo_);
540 // only consider the changebar space if we're drawing outer left
542 x += CHANGEBAR_MARGIN;
543 int const h = yo_ + row_->height() - 1 - (i - next_depth - 1) * 3;
545 pain_.line(x, yo_, x, h, LColor::depthbar);
548 pain_.fillRectangle(x, yo_, w, 2, LColor::depthbar);
550 pain_.fillRectangle(x, h, w, 2, LColor::depthbar);
555 int RowPainter::paintLengthMarker(string const & prefix, VSpace const & vsp, int start)
557 if (vsp.kind() == VSpace::NONE)
560 int const arrow_size = 4;
561 int const size = getLengthMarkerHeight(bv_, vsp);
562 int const end = start + size;
564 // the label to display (if any)
566 // y-values for top arrow
568 // y-values for bottom arrow
571 str = prefix + " (" + vsp.asLyXCommand() + ")";
573 if (vsp.kind() == VSpace::VFILL) {
577 // adding or removing space
578 bool const added = vsp.kind() != VSpace::LENGTH ||
579 vsp.length().len().value() > 0.0;
580 ty1 = added ? (start + arrow_size) : start;
581 ty2 = added ? start : (start + arrow_size);
582 by1 = added ? (end - arrow_size) : end;
583 by2 = added ? end : (end - arrow_size);
586 int const leftx = int(xo_) + leftMargin();
587 int const midx = leftx + arrow_size;
588 int const rightx = midx + arrow_size;
596 font.setColor(LColor::added_space).decSize().decSize();
597 font_metrics::rectText(str, font, w, a, d);
599 pain_.rectText(leftx + 2 * arrow_size + 5,
600 start + ((end - start) / 2) + d,
604 pain_.line(leftx, ty1, midx, ty2, LColor::added_space);
605 pain_.line(midx, ty2, rightx, ty1, LColor::added_space);
608 pain_.line(leftx, by1, midx, by2, LColor::added_space);
609 pain_.line(midx, by2, rightx, by1, LColor::added_space);
612 pain_.line(midx, ty2, midx, by2, LColor::added_space);
618 int RowPainter::paintPageBreak(string const & label, int y)
621 pb_font.setColor(LColor::pagebreak).decSize();
626 font_metrics::rectText(label, pb_font, w, a, d);
628 int const text_start = int(xo_ + (width_ - w) / 2);
629 int const text_end = text_start + w;
631 pain_.rectText(text_start, y + d, label, pb_font);
633 pain_.line(int(xo_), y, text_start, y,
634 LColor::pagebreak, Painter::line_onoffdash);
635 pain_.line(text_end, y, int(xo_ + width_), y,
636 LColor::pagebreak, Painter::line_onoffdash);
638 return 3 * defaultRowHeight();
642 int RowPainter::paintAppendixStart(int y)
645 pb_font.setColor(LColor::appendix).decSize();
647 string const label = _("Appendix");
651 font_metrics::rectText(label, pb_font, w, a, d);
653 int const text_start = int(xo_ + (width_ - w) / 2);
654 int const text_end = text_start + w;
656 pain_.rectText(text_start, y + d, label, pb_font);
658 pain_.line(int(xo_ + 1), y, text_start, y, LColor::appendix);
659 pain_.line(text_end, y, int(xo_ + width_ - 2), y, LColor::appendix);
661 return 3 * defaultRowHeight();
665 void RowPainter::paintFirst()
667 ParagraphParameters const & parparams = pit_->params();
671 // start of appendix?
672 if (parparams.startOfAppendix())
673 y_top += paintAppendixStart(yo_ + y_top + 2 * defaultRowHeight());
676 if (row_ == text_.firstRow() && !text_.isInInset())
677 y_top += PAPER_MARGIN;
679 // draw a top pagebreak
680 if (parparams.pagebreakTop())
681 y_top += paintPageBreak(_("Page Break (top)"),
682 yo_ + y_top + 2 * defaultRowHeight());
684 // draw the additional space if needed:
685 y_top += paintLengthMarker(_("Space above"), parparams.spaceTop(),
688 Buffer const & buffer = *bv_.buffer();
690 LyXLayout_ptr const & layout = pit_->layout();
692 if (buffer.params.paragraph_separation == BufferParams::PARSEP_SKIP) {
693 if (pit_ != text_.ownerParagraphs().begin()) {
694 if (layout->latextype == LATEX_PARAGRAPH
695 && !pit_->getDepth()) {
696 y_top += buffer.params.getDefSkip().inPixels(bv_);
698 LyXLayout_ptr const & playout =
699 boost::prior(pit_)->layout();
700 if (playout->latextype == LATEX_PARAGRAPH
701 && !boost::prior(pit_)->getDepth()) {
702 // is it right to use defskip here, too? (AS)
703 y_top += buffer.params.getDefSkip().inPixels(bv_);
709 int const ww = bv_.workWidth();
712 if (parparams.lineTop()) {
713 int const asc = font_metrics::ascent('x', getFont(0));
717 int const w = (text_.isInInset() ? text_.inset_owner->width() : 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(pit_, *bv_.buffer(), *row_)) / 2;
802 x -= font_metrics::width(str, font) / 2;
804 x = ww - leftMargin() -
805 font_metrics::width(str, font);
808 yo_ + row_->baseline() - row_->ascent_of_text() - maxdesc,
815 void RowPainter::paintLast()
817 ParagraphParameters const & parparams = pit_->params();
818 int y_bottom = row_->height() - 1;
821 if (row_ == text_.lastRow() && !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 int const asc = font_metrics::ascent('x',
840 getFont(max(pos_type(0), pit_->size() - 1)));
844 int const w = text_.isInInset() ? text_.inset_owner->width() : ww;
845 int const xp = int(text_.isInInset() ? xo_ : 0);
846 int const y = yo_ + y_bottom;
847 pain_.line(xp, y, xp + w, y, LColor::topline, Painter::line_solid,
848 Painter::line_thick);
853 bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params);
854 int const endlabel = getEndLabel(pit_, text_.ownerParagraphs());
859 case END_LABEL_FILLED_BOX:
861 LyXFont const font = getLabelFont();
862 int const size = int(0.75 * font_metrics::maxAscent(font));
863 int const y = (yo_ + row_->baseline()) - size;
864 int x = is_rtl ? LEFT_MARGIN : ww - PAPER_MARGIN - size;
866 if (row_->fill() <= size)
867 x += (size - row_->fill() + 1) * (is_rtl ? -1 : 1);
869 if (endlabel == END_LABEL_BOX)
870 pain_.rectangle(x, y, size, size, LColor::eolmarker);
872 pain_.fillRectangle(x, y, size, size, LColor::eolmarker);
875 case END_LABEL_STATIC:
877 LyXFont font = getLabelFont();
878 string const & str = pit_->layout()->endlabelstring();
879 double const x = is_rtl ?
880 x_ - font_metrics::width(str, font)
881 : ww - text_.rightMargin(pit_, *bv_.buffer(), *row_) - row_->fill();
882 pain_.text(int(x), yo_ + row_->baseline(), str, font);
885 case END_LABEL_NO_LABEL:
891 void RowPainter::paintText()
893 pos_type const last = lastPos(*pit_, row_);
894 pos_type body_pos = pit_->beginningOfBody();
896 (body_pos - 1 > last || !pit_->isLineSeparator(body_pos - 1))) {
900 LyXLayout_ptr const & layout = pit_->layout();
902 bool running_strikeout = false;
903 bool is_struckout = false;
904 int last_strikeout_x = 0;
906 pos_type vpos = row_->pos();
907 while (vpos <= last) {
908 if (x_ > bv_.workWidth())
910 pos_type pos = text_.vis2log(vpos);
912 if (pos >= pit_->size()) {
917 if (x_ + singleWidth(pos) < 0) {
918 x_ += singleWidth(pos);
923 is_struckout = isDeletedText(*pit_, pos);
925 if (is_struckout && !running_strikeout) {
926 running_strikeout = true;
927 last_strikeout_x = int(x_);
930 bool const highly_editable_inset = pit_->isInset(pos)
931 && isHighlyEditableInset(pit_->getInset(pos));
933 // if we reach the end of a struck out range, paint it
934 // we also don't paint across things like tables
935 if (running_strikeout && (highly_editable_inset || !is_struckout)) {
936 int const middle = yo_ + row_->top_of_text()
937 + (row_->baseline() - row_->top_of_text()) / 2;
938 pain_.line(last_strikeout_x, middle, int(x_), middle,
939 LColor::strikeout, Painter::line_solid, Painter::line_thin);
940 running_strikeout = false;
943 if (body_pos > 0 && pos == body_pos - 1) {
944 int const lwidth = font_metrics::width(layout->labelsep,
947 x_ += label_hfill_ + lwidth - singleWidth(body_pos - 1);
950 if (pit_->isHfill(pos)) {
953 int const y0 = yo_ + row_->baseline();
954 int const y1 = y0 - defaultRowHeight() / 2;
956 pain_.line(int(x_), y1, int(x_), y0, LColor::added_space);
958 if (hfillExpansion(*pit_, row_, pos)) {
959 int const y2 = (y0 + y1) / 2;
961 if (pos >= body_pos) {
962 pain_.line(int(x_), y2, int(x_ + hfill_), y2,
964 Painter::line_onoffdash);
967 pain_.line(int(x_), y2, int(x_ + label_hfill_), y2,
969 Painter::line_onoffdash);
972 pain_.line(int(x_), y1, int(x_), y0, LColor::added_space);
976 } else if (pit_->isSeparator(pos)) {
977 x_ += singleWidth(pos);
986 // if we reach the end of a struck out range, paint it
987 if (running_strikeout) {
988 int const middle = yo_ + row_->top_of_text()
989 + ((row_->baseline() - row_->top_of_text()) / 2);
990 pain_.line(last_strikeout_x, middle, int(x_), middle,
991 LColor::strikeout, Painter::line_solid, Painter::line_thin);
992 running_strikeout = false;
997 void RowPainter::paint()
999 width_ = text_.workWidth();
1001 separator_ = row_->fill_separator();
1002 hfill_ = row_->fill_hfill();
1003 label_hfill_ = row_->fill_label_hfill();
1005 // FIXME: what is this fixing ?
1006 if (text_.isInInset() && x_ < 0)
1010 // If we're *not* at the top-level of rows, then the
1011 // background has already been cleared.
1012 if (&text_ == bv_.text)
1015 // paint the selection background
1016 if (text_.selection.set())
1019 // vertical lines for appendix
1022 // environment depth brackets
1028 if (row_->isParStart())
1031 if (isParEnd(*pit_, row_))
1039 int paintRows(BufferView const & bv, LyXText const & text,
1040 ParagraphList::iterator pit, RowList::iterator rit,
1041 int xo, int y, int yf, int yo)
1043 //lyxerr << " paintRows: rit: " << &*rit << endl;
1044 //const_cast<LyXText&>(text).updateRowPositions();
1045 int const yy = yf - y;
1046 int const y2 = bv.painter().paperHeight();
1048 ParagraphList::iterator end = text.ownerParagraphs().end();
1049 bool active = false;
1051 for ( ; pit != end; ++pit) {
1052 RowList::iterator row = pit->rows.begin();
1053 RowList::iterator rend = pit->rows.end();
1055 for ( ; row != rend; ++row) {
1059 RowPainter painter(bv, text, pit, row, y + yo, xo, y + bv.top_y());
1065 //lyxerr << " paintRows: row: " << &*row << " ignored" << endl;
1076 int paintText(BufferView & bv)
1078 int const topy = bv.top_y();
1079 ParagraphList::iterator pit;
1080 RowList::iterator rit = bv.text->getRowNearY(topy, pit);
1081 int y = rit->y() - topy;
1082 return paintRows(bv, *bv.text, pit, rit, 0, y, y, 0);
1086 void paintTextInset(BufferView & bv, LyXText & text, int x, int baseline)
1088 RowList::iterator rit = text.firstRow();
1089 RowList::iterator end = text.endRow();
1090 ParagraphList::iterator pit = text.ownerParagraphs().begin();
1092 int y_offset = baseline - rit->ascent_of_text();
1094 while (rit != end && y + rit->height() <= 0) {
1096 text.nextRow(pit, rit);
1099 paintRows(bv, text, pit, rit, x, 0, y, y);
1101 paintRows(bv, text, pit, rit, x, 0, y_offset, y_offset);
1105 int getLengthMarkerHeight(BufferView const & bv, VSpace const & vsp)
1107 if (vsp.kind() == VSpace::NONE)
1110 int const arrow_size = 4;
1111 int const space_size = vsp.inPixels(bv);
1115 int const min_size = max(3 * arrow_size,
1116 font_metrics::maxAscent(font)
1117 + font_metrics::maxDescent(font));
1119 if (vsp.length().len().value() < 0.0)
1122 return max(min_size, space_size);