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);
602 font_metrics::rectText(str, font, w, a, d);
604 pain_.rectText(leftx + 2 * arrow_size + 5,
605 start + ((end - start) / 2) + d,
607 LColor::none, LColor::none);
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);
633 font_metrics::rectText(label, pb_font, w, a, d);
635 int const text_start = int(xo_ + (width_ - w) / 2);
636 int const text_end = text_start + w;
638 pain_.rectText(text_start, y + d, label, pb_font, LColor::none, LColor::none);
640 pain_.line(int(xo_), y, text_start, y,
641 LColor::pagebreak, Painter::line_onoffdash);
642 pain_.line(text_end, y, int(xo_ + width_), y,
643 LColor::pagebreak, Painter::line_onoffdash);
645 return 3 * defaultRowHeight();
649 int RowPainter::paintAppendixStart(int y)
652 pb_font.setColor(LColor::appendix);
655 string const label = _("Appendix");
659 font_metrics::rectText(label, pb_font, w, a, d);
661 int const text_start = int(xo_ + (width_ - w) / 2);
662 int const text_end = text_start + w;
664 pain_.rectText(text_start, y + d, label, pb_font, LColor::none, LColor::none);
666 pain_.line(int(xo_ + 1), y, text_start, y, LColor::appendix);
667 pain_.line(text_end, y, int(xo_ + width_ - 2), y, LColor::appendix);
669 return 3 * defaultRowHeight();
673 void RowPainter::paintFirst()
675 ParagraphParameters const & parparams = pit_->params();
679 // start of appendix?
680 if (parparams.startOfAppendix())
681 y_top += paintAppendixStart(yo_ + y_top + 2 * defaultRowHeight());
684 if (row_ == text_.firstRow() && !text_.isInInset())
685 y_top += PAPER_MARGIN;
687 // draw a top pagebreak
688 if (parparams.pagebreakTop())
689 y_top += paintPageBreak(_("Page Break (top)"),
690 yo_ + y_top + 2 * defaultRowHeight());
692 // draw the additional space if needed:
693 y_top += paintLengthMarker(_("Space above"), parparams.spaceTop(),
696 Buffer const & buffer = *bv_.buffer();
698 LyXLayout_ptr const & layout = pit_->layout();
700 if (buffer.params().paragraph_separation == BufferParams::PARSEP_SKIP) {
701 if (pit_ != text_.ownerParagraphs().begin()) {
702 if (layout->latextype == LATEX_PARAGRAPH
703 && !pit_->getDepth()) {
704 y_top += buffer.params().getDefSkip().inPixels(bv_);
706 LyXLayout_ptr const & playout =
707 boost::prior(pit_)->layout();
708 if (playout->latextype == LATEX_PARAGRAPH
709 && !boost::prior(pit_)->getDepth()) {
710 // is it right to use defskip here, too? (AS)
711 y_top += buffer.params().getDefSkip().inPixels(bv_);
717 int const ww = bv_.workWidth();
720 if (parparams.lineTop()) {
721 int const asc = font_metrics::ascent('x', getFont(0));
725 int const w = (text_.isInInset() ? text_.inset_owner->width() : ww);
726 int const xp = static_cast<int>(text_.isInInset() ? xo_ : 0);
727 pain_.line(xp, yo_ + y_top, xp + w, yo_ + y_top,
728 LColor::topline, Painter::line_solid,
729 Painter::line_thick);
734 bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params());
736 // should we print a label?
737 if (layout->labeltype >= LABEL_STATIC
738 && (layout->labeltype != LABEL_STATIC
739 || layout->latextype != LATEX_ENVIRONMENT
740 || isFirstInSequence(pit_, text_.ownerParagraphs()))) {
742 LyXFont font = getLabelFont();
743 if (!pit_->getLabelstring().empty()) {
745 string const str = pit_->getLabelstring();
747 // this is special code for the chapter layout. This is
748 // printed in an extra row and has a pagebreak at
750 if (layout->counter == "chapter") {
751 if (buffer.params().secnumdepth >= 0) {
752 float spacing_val = 1.0;
753 if (!parparams.spacing().isDefault()) {
754 spacing_val = parparams.spacing().getValue();
756 spacing_val = buffer.params().spacing().getValue();
760 int(font_metrics::maxDescent(font) * layout->spacing.getValue() * spacing_val)
761 + int(layout->parsep) * defaultRowHeight();
764 x = ww - leftMargin() -
765 font_metrics::width(str, font);
769 yo_ + row_->baseline() -
770 row_->ascent_of_text() - maxdesc,
775 x = ww - leftMargin()
776 + font_metrics::width(layout->labelsep, font);
778 x = x_ - font_metrics::width(layout->labelsep, font)
779 - font_metrics::width(str, font);
782 pain_.text(int(x), yo_ + row_->baseline(), str, font);
786 // the labels at the top of an environment.
787 // More or less for bibliography
788 } else if (isFirstInSequence(pit_, text_.ownerParagraphs()) &&
789 (layout->labeltype == LABEL_TOP_ENVIRONMENT ||
790 layout->labeltype == LABEL_BIBLIO ||
791 layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)) {
792 LyXFont font = getLabelFont();
793 if (!pit_->getLabelstring().empty()) {
794 string const str = pit_->getLabelstring();
795 float spacing_val = 1.0;
796 if (!parparams.spacing().isDefault()) {
797 spacing_val = parparams.spacing().getValue();
799 spacing_val = buffer.params().spacing().getValue();
803 int(font_metrics::maxDescent(font) * layout->spacing.getValue() * spacing_val
804 + (layout->labelbottomsep * defaultRowHeight()));
807 if (layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
808 x = ((is_rtl ? leftMargin() : x_)
809 + ww - text_.rightMargin(pit_, *bv_.buffer(), *row_)) / 2;
810 x -= font_metrics::width(str, font) / 2;
812 x = ww - leftMargin() -
813 font_metrics::width(str, font);
816 yo_ + row_->baseline() - row_->ascent_of_text() - maxdesc,
823 void RowPainter::paintLast()
825 ParagraphParameters const & parparams = pit_->params();
826 int y_bottom = row_->height() - 1;
829 if (row_ == text_.lastRow() && !text_.isInInset())
830 y_bottom -= PAPER_MARGIN;
832 int const ww = bv_.workWidth();
834 // draw a bottom pagebreak
835 if (parparams.pagebreakBottom()) {
836 y_bottom -= paintPageBreak(_("Page Break (bottom)"),
837 yo_ + y_bottom - 2 * defaultRowHeight());
840 // draw the additional space if needed:
841 int const height = getLengthMarkerHeight(bv_, parparams.spaceBottom());
842 y_bottom -= paintLengthMarker(_("Space below"), parparams.spaceBottom(),
843 yo_ + y_bottom - height);
845 // draw a bottom line
846 if (parparams.lineBottom()) {
847 int const asc = font_metrics::ascent('x',
848 getFont(max(pos_type(0), pit_->size() - 1)));
852 int const w = text_.isInInset() ? text_.inset_owner->width() : ww;
853 int const xp = int(text_.isInInset() ? xo_ : 0);
854 int const y = yo_ + y_bottom;
855 pain_.line(xp, y, xp + w, y, LColor::topline, Painter::line_solid,
856 Painter::line_thick);
861 bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params());
862 int const endlabel = getEndLabel(pit_, text_.ownerParagraphs());
867 case END_LABEL_FILLED_BOX:
869 LyXFont const font = getLabelFont();
870 int const size = int(0.75 * font_metrics::maxAscent(font));
871 int const y = (yo_ + row_->baseline()) - size;
872 int x = is_rtl ? LEFT_MARGIN : ww - PAPER_MARGIN - size;
874 if (row_->fill() <= size)
875 x += (size - row_->fill() + 1) * (is_rtl ? -1 : 1);
877 if (endlabel == END_LABEL_BOX)
878 pain_.rectangle(x, y, size, size, LColor::eolmarker);
880 pain_.fillRectangle(x, y, size, size, LColor::eolmarker);
883 case END_LABEL_STATIC:
885 LyXFont font = getLabelFont();
886 string const & str = pit_->layout()->endlabelstring();
887 double const x = is_rtl ?
888 x_ - font_metrics::width(str, font)
889 : ww - text_.rightMargin(pit_, *bv_.buffer(), *row_) - row_->fill();
890 pain_.text(int(x), yo_ + row_->baseline(), str, font);
893 case END_LABEL_NO_LABEL:
899 void RowPainter::paintText()
901 pos_type const last = lastPos(*pit_, row_);
902 pos_type body_pos = pit_->beginningOfBody();
904 (body_pos - 1 > last || !pit_->isLineSeparator(body_pos - 1))) {
908 LyXLayout_ptr const & layout = pit_->layout();
910 bool running_strikeout = false;
911 bool is_struckout = false;
912 int last_strikeout_x = 0;
914 pos_type vpos = row_->pos();
915 while (vpos <= last) {
916 if (x_ > bv_.workWidth())
918 pos_type pos = text_.vis2log(vpos);
920 if (pos >= pit_->size()) {
925 if (x_ + singleWidth(pos) < 0) {
926 x_ += singleWidth(pos);
931 is_struckout = isDeletedText(*pit_, pos);
933 if (is_struckout && !running_strikeout) {
934 running_strikeout = true;
935 last_strikeout_x = int(x_);
938 bool const highly_editable_inset = pit_->isInset(pos)
939 && isHighlyEditableInset(pit_->getInset(pos));
941 // if we reach the end of a struck out range, paint it
942 // we also don't paint across things like tables
943 if (running_strikeout && (highly_editable_inset || !is_struckout)) {
944 int const middle = yo_ + row_->top_of_text()
945 + (row_->baseline() - row_->top_of_text()) / 2;
946 pain_.line(last_strikeout_x, middle, int(x_), middle,
947 LColor::strikeout, Painter::line_solid, Painter::line_thin);
948 running_strikeout = false;
951 if (body_pos > 0 && pos == body_pos - 1) {
952 int const lwidth = font_metrics::width(layout->labelsep,
955 x_ += label_hfill_ + lwidth - singleWidth(body_pos - 1);
958 if (pit_->isHfill(pos)) {
961 int const y0 = yo_ + row_->baseline();
962 int const y1 = y0 - defaultRowHeight() / 2;
964 pain_.line(int(x_), y1, int(x_), y0, LColor::added_space);
966 if (hfillExpansion(*pit_, row_, pos)) {
967 int const y2 = (y0 + y1) / 2;
969 if (pos >= body_pos) {
970 pain_.line(int(x_), y2, int(x_ + hfill_), y2,
972 Painter::line_onoffdash);
975 pain_.line(int(x_), y2, int(x_ + label_hfill_), y2,
977 Painter::line_onoffdash);
980 pain_.line(int(x_), y1, int(x_), y0, LColor::added_space);
984 } else if (pit_->isSeparator(pos)) {
985 x_ += singleWidth(pos);
994 // if we reach the end of a struck out range, paint it
995 if (running_strikeout) {
996 int const middle = yo_ + row_->top_of_text()
997 + ((row_->baseline() - row_->top_of_text()) / 2);
998 pain_.line(last_strikeout_x, middle, int(x_), middle,
999 LColor::strikeout, Painter::line_solid, Painter::line_thin);
1000 running_strikeout = false;
1005 void RowPainter::paint()
1007 width_ = text_.workWidth();
1009 separator_ = row_->fill_separator();
1010 hfill_ = row_->fill_hfill();
1011 label_hfill_ = row_->fill_label_hfill();
1013 // FIXME: what is this fixing ?
1014 if (text_.isInInset() && x_ < 0)
1018 // If we're *not* at the top-level of rows, then the
1019 // background has already been cleared.
1020 if (&text_ == bv_.text)
1023 // paint the selection background
1024 if (text_.selection.set())
1027 // vertical lines for appendix
1030 // environment depth brackets
1036 if (row_->isParStart())
1039 if (isParEnd(*pit_, row_))
1047 int paintRows(BufferView const & bv, LyXText const & text,
1048 ParagraphList::iterator pit, RowList::iterator rit,
1049 int xo, int y, int yf, int yo)
1051 //lyxerr << " paintRows: rit: " << &*rit << endl;
1052 //const_cast<LyXText&>(text).updateRowPositions();
1053 int const yy = yf - y;
1054 int const y2 = bv.painter().paperHeight();
1056 ParagraphList::iterator end = text.ownerParagraphs().end();
1057 bool active = false;
1059 for ( ; pit != end; ++pit) {
1060 RowList::iterator row = pit->rows.begin();
1061 RowList::iterator rend = pit->rows.end();
1063 for ( ; row != rend; ++row) {
1067 RowPainter painter(bv, text, pit, row, y + yo, xo, y + bv.top_y());
1073 //lyxerr << " paintRows: row: " << &*row << " ignored" << endl;
1084 int paintText(BufferView & bv)
1086 int const topy = bv.top_y();
1087 ParagraphList::iterator pit;
1088 RowList::iterator rit = bv.text->getRowNearY(topy, pit);
1089 int y = rit->y() - topy;
1090 return paintRows(bv, *bv.text, pit, rit, 0, y, y, 0);
1094 void paintTextInset(BufferView & bv, LyXText & text, int x, int baseline)
1096 RowList::iterator rit = text.firstRow();
1097 RowList::iterator end = text.endRow();
1098 ParagraphList::iterator pit = text.ownerParagraphs().begin();
1100 int y_offset = baseline - rit->ascent_of_text();
1102 while (rit != end && y + rit->height() <= 0) {
1104 text.nextRow(pit, rit);
1107 paintRows(bv, text, pit, rit, x, 0, y, y);
1109 paintRows(bv, text, pit, rit, x, 0, y_offset, y_offset);
1113 int getLengthMarkerHeight(BufferView const & bv, VSpace const & vsp)
1115 if (vsp.kind() == VSpace::NONE)
1118 int const arrow_size = 4;
1119 int const space_size = vsp.inPixels(bv);
1123 int const min_size = max(3 * arrow_size,
1124 font_metrics::maxAscent(font)
1125 + font_metrics::maxDescent(font));
1127 if (vsp.length().len().value() < 0.0)
1130 return max(min_size, space_size);