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"
25 #include "lyxrow_funcs.h"
26 #include "metricsinfo.h"
27 #include "paragraph.h"
28 #include "paragraph_funcs.h"
29 #include "ParagraphParameters.h"
32 #include "frontends/font_metrics.h"
33 #include "frontends/Painter.h"
35 #include "insets/insettext.h"
37 #include "support/textutils.h"
44 extern int PAPER_MARGIN;
45 extern int CHANGEBAR_MARGIN;
46 extern int LEFT_MARGIN;
50 // "temporary". We'll never get to use more
51 // references until we start adding hacks like
52 // these until other places catch up.
53 BufferView * perv(BufferView const & bv)
55 return const_cast<BufferView *>(&bv);
59 * A class used for painting an individual row of text.
63 /// initialise painter
64 RowPainter(BufferView const & bv, LyXText const & text,
65 ParagraphList::iterator pit,
66 RowList::iterator rit, int y_offset, int x_offset, int y);
71 // paint various parts
72 void paintBackground();
73 void paintSelection();
76 void paintChangeBar();
79 void paintForeignMark(double orig_x, LyXFont const & orig_font);
80 void paintHebrewComposeChar(lyx::pos_type & vpos);
81 void paintArabicComposeChar(lyx::pos_type & vpos);
82 void paintChars(lyx::pos_type & vpos, bool hebrew, bool arabic);
83 int paintPageBreak(string const & label, int y);
84 int paintAppendixStart(int y);
85 int paintLengthMarker(string const & prefix, VSpace const & vsp, int start);
87 void paintFromPos(lyx::pos_type & vpos);
88 void paintInset(lyx::pos_type const pos);
90 /// return left margin
91 int leftMargin() const;
93 /// return the font at the given pos
94 LyXFont const getFont(lyx::pos_type pos) const;
96 /// return the label font for this row
97 LyXFont const getLabelFont() const;
99 char const transformChar(char c, lyx::pos_type pos) const;
101 /// return pixel width for the given pos
102 int singleWidth(lyx::pos_type pos) const;
103 int singleWidth(lyx::pos_type pos, char c) const;
105 /// bufferview to paint on
106 BufferView const & bv_;
111 /// LyXText for the row
112 LyXText const & text_;
115 RowList::iterator row_;
118 mutable ParagraphList::iterator pit_;
132 RowPainter::RowPainter(BufferView const & bv, LyXText const & text,
133 ParagraphList::iterator pit, RowList::iterator rit,
134 int y_offset, int x_offset, int y)
135 : bv_(bv), pain_(bv_.painter()), text_(text), row_(rit),
136 pit_(pit), xo_(x_offset), yo_(y_offset), y_(y)
141 LyXFont const RowPainter::getFont(pos_type pos) const
143 return text_.getFont(pit_, pos);
147 int RowPainter::singleWidth(lyx::pos_type pos) const
149 return text_.singleWidth(pit_, pos);
153 int RowPainter::singleWidth(lyx::pos_type pos, char c) const
155 LyXFont const & font = text_.getFont(pit_, pos);
156 return text_.singleWidth(pit_, pos, c, font);
160 LyXFont const RowPainter::getLabelFont() const
162 return text_.getLabelFont(pit_);
166 char const RowPainter::transformChar(char c, lyx::pos_type pos) const
168 return text_.transformChar(c, *pit_, pos);
172 int RowPainter::leftMargin() const
174 return text_.leftMargin(pit_, *row_);
178 void RowPainter::paintInset(pos_type const pos)
180 InsetOld * inset = const_cast<InsetOld*>(pit_->getInset(pos));
184 PainterInfo pi(perv(bv_));
185 pi.base.font = getFont(pos);
186 inset->draw(pi, int(x_), yo_ + row_->baseline());
187 x_ += inset->width();
191 void RowPainter::paintHebrewComposeChar(pos_type & vpos)
193 pos_type pos = text_.vis2log(vpos);
198 char c = pit_->getChar(pos);
202 LyXFont const & font = getFont(pos);
203 int const width = font_metrics::width(c, font);
206 for (pos_type i = pos - 1; i >= 0; --i) {
207 c = pit_->getChar(i);
208 if (!Encodings::IsComposeChar_hebrew(c)) {
209 if (IsPrintableNonspace(c)) {
213 dx = (c == 'ø' || c == 'ã')
215 : (width2 - width) / 2;
222 pain_.text(int(x_) + dx, yo_ + row_->baseline(), str, font);
226 void RowPainter::paintArabicComposeChar(pos_type & vpos)
228 pos_type pos = text_.vis2log(vpos);
232 char c = pit_->getChar(pos);
233 c = transformChar(c, pos);
237 LyXFont const & font = getFont(pos);
238 int const width = font_metrics::width(c, font);
241 for (pos_type i = pos - 1; i >= 0; --i) {
242 c = pit_->getChar(i);
243 if (!Encodings::IsComposeChar_arabic(c)) {
244 if (IsPrintableNonspace(c)) {
247 dx = (width2 - width) / 2;
253 pain_.text(int(x_) + dx, yo_ + row_->baseline(), str, font);
257 void RowPainter::paintChars(pos_type & vpos, bool hebrew, bool arabic)
259 pos_type pos = text_.vis2log(vpos);
260 pos_type const last = lastPos(*pit_, row_);
261 LyXFont orig_font = getFont(pos);
265 str += pit_->getChar(pos);
267 unsigned char c = str[0];
268 str[0] = transformChar(c, pos);
271 bool prev_struckout(isDeletedText(*pit_, pos));
272 bool prev_newtext(isInsertedText(*pit_, pos));
276 // collect as much similar chars as we can
277 while (vpos <= last && (pos = text_.vis2log(vpos)) >= 0) {
278 char c = pit_->getChar(pos);
280 if (!IsPrintableNonspace(c))
283 if (prev_struckout != isDeletedText(*pit_, pos))
286 if (prev_newtext != isInsertedText(*pit_, pos))
289 if (arabic && Encodings::IsComposeChar_arabic(c))
291 if (hebrew && Encodings::IsComposeChar_hebrew(c))
294 if (orig_font != getFont(pos))
298 c = transformChar(c, pos);
303 if (prev_struckout) {
304 orig_font.setColor(LColor::strikeout);
305 } else if (prev_newtext) {
306 orig_font.setColor(LColor::newtext);
309 // Draw text and set the new x position
310 //lyxerr << "paint row: yo_ " << yo_ << " baseline: " << row_->baseline()
312 pain_.text(int(x_), yo_ + row_->baseline(), str, orig_font);
313 x_ += font_metrics::width(str, orig_font);
317 void RowPainter::paintForeignMark(double orig_x, LyXFont const & orig_font)
319 if (!lyxrc.mark_foreign_language)
321 if (orig_font.language() == latex_language)
323 if (orig_font.language() == bv_.buffer()->params().language)
326 int const y = yo_ + row_->baseline() + 1;
327 pain_.line(int(orig_x), y, int(x_), y, LColor::language);
331 void RowPainter::paintFromPos(pos_type & vpos)
333 pos_type const pos = text_.vis2log(vpos);
335 LyXFont const & orig_font = getFont(pos);
337 double const orig_x = x_;
339 char const c = pit_->getChar(pos);
341 if (c == Paragraph::META_INSET) {
344 paintForeignMark(orig_x, orig_font);
348 // usual characters, no insets
350 // special case languages
351 bool const hebrew = (orig_font.language()->lang() == "hebrew");
353 orig_font.language()->lang() == "arabic" &&
354 (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
355 lyxrc.font_norm_type == LyXRC::ISO_10646_1);
357 // draw as many chars as we can
358 if ((!hebrew && !arabic)
359 || (hebrew && !Encodings::IsComposeChar_hebrew(c))
360 || (arabic && !Encodings::IsComposeChar_arabic(c))) {
361 paintChars(vpos, hebrew, arabic);
363 paintHebrewComposeChar(vpos);
365 paintArabicComposeChar(vpos);
368 paintForeignMark(orig_x, orig_font);
374 void RowPainter::paintBackground()
376 int const x = int(xo_);
377 int const y = yo_ < 0 ? 0 : yo_;
378 int const h = yo_ < 0 ? row_->height() + yo_ : row_->height();
379 pain_.fillRectangle(x, y, width_, h, text_.backgroundColor());
383 void RowPainter::paintSelection()
385 bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params());
387 // the current selection
388 int const startx = text_.selection.start.x();
389 int const endx = text_.selection.end.x();
390 int const starty = text_.selection.start.y();
391 int const endy = text_.selection.end.y();
392 RowList::iterator startrow = text_.getRow(text_.selection.start);
393 RowList::iterator endrow = text_.getRow(text_.selection.end);
395 if (text_.bidi_same_direction) {
399 int h = row_->height();
401 if (startrow == row_ && endrow == row_) {
403 x = int(xo_) + startx;
405 pain_.fillRectangle(x, y, w, h, LColor::selection);
409 pain_.fillRectangle(x, y, w, h, LColor::selection);
411 } else if (startrow == row_) {
412 int const x = is_rtl ? int(xo_) : int(xo_ + startx);
413 int const w = is_rtl ? startx : (width_ - startx);
414 pain_.fillRectangle(x, y, w, h, LColor::selection);
415 } else if (endrow == row_) {
416 int const x = is_rtl ? int(xo_ + endx) : int(xo_);
417 int const w = is_rtl ? (width_ - endx) : endx;
418 pain_.fillRectangle(x, y, w, h, LColor::selection);
419 } else if (y_ > starty && y_ < endy) {
420 pain_.fillRectangle(int(xo_), y, width_, h, LColor::selection);
423 } else if (startrow != row_ && endrow != row_) {
424 if (y_ > starty && y_ < endy) {
426 int h = row_->height();
427 pain_.fillRectangle(int(xo_), yo_, w, h, LColor::selection);
432 if ((startrow != row_ && !is_rtl) || (endrow != row_ && is_rtl))
433 pain_.fillRectangle(int(xo_), yo_,
434 int(x_), row_->height(), LColor::selection);
436 pos_type const body_pos = pit_->beginningOfBody();
437 pos_type const last = lastPos(*pit_, row_);
440 for (pos_type vpos = row_->pos(); vpos <= last; ++vpos) {
441 pos_type pos = text_.vis2log(vpos);
442 double const old_tmpx = tmpx;
443 if (body_pos > 0 && pos == body_pos - 1) {
444 LyXLayout_ptr const & layout = pit_->layout();
445 LyXFont const lfont = getLabelFont();
447 tmpx += label_hfill_ + font_metrics::width(layout->labelsep, lfont);
449 if (pit_->isLineSeparator(body_pos - 1))
450 tmpx -= singleWidth(body_pos - 1);
453 if (hfillExpansion(*pit_, row_, pos)) {
454 tmpx += singleWidth(pos);
458 tmpx += label_hfill_;
461 else if (pit_->isSeparator(pos)) {
462 tmpx += singleWidth(pos);
466 tmpx += singleWidth(pos);
469 if ((startrow != row_ || text_.selection.start.pos() <= pos) &&
470 (endrow != row_ || pos < text_.selection.end.pos())) {
471 // Here we do not use x_ as xo_ was added to x_.
472 pain_.fillRectangle(int(old_tmpx), yo_,
473 int(tmpx - old_tmpx + 1),
474 row_->height(), LColor::selection);
478 if ((startrow != row_ && is_rtl) || (endrow != row_ && !is_rtl)) {
479 pain_.fillRectangle(int(xo_ + tmpx),
480 yo_, int(bv_.workWidth() - tmpx),
481 row_->height(), LColor::selection);
486 void RowPainter::paintChangeBar()
488 pos_type const start = row_->pos();
489 pos_type const end = lastPos(*pit_, row_);
491 if (!pit_->isChanged(start, end))
494 int const height = (row_ == text_.lastRow())
496 : row_->height() + boost::next(row_)->top_of_text();
498 pain_.fillRectangle(4, yo_, 5, height, LColor::changebar);
502 void RowPainter::paintAppendix()
504 if (!pit_->params().appendix())
507 // FIXME: can be just width_ ?
508 int const ww = bv_.workWidth();
512 if (pit_->params().startOfAppendix())
513 y += 2 * defaultRowHeight();
515 pain_.line(1, y, 1, yo_ + row_->height(), LColor::appendix);
516 pain_.line(ww - 2, y, ww - 2, yo_ + row_->height(), LColor::appendix);
520 void RowPainter::paintDepthBar()
522 Paragraph::depth_type const depth = pit_->getDepth();
527 Paragraph::depth_type prev_depth = 0;
528 if (row_ != text_.firstRow()) {
529 ParagraphList::iterator pit2 = pit_;
530 if (row_ == pit2->rows.begin())
532 prev_depth = pit2->getDepth();
535 Paragraph::depth_type next_depth = 0;
536 if (row_ != text_.lastRow()) {
537 ParagraphList::iterator pit2 = pit_;
538 if (boost::next(row_) == pit2->rows.end())
540 next_depth = pit2->getDepth();
543 for (Paragraph::depth_type i = 1; i <= depth; ++i) {
544 int const w = PAPER_MARGIN / 5;
545 int x = int(w * i + xo_);
546 // only consider the changebar space if we're drawing outer left
548 x += CHANGEBAR_MARGIN;
549 int const h = yo_ + row_->height() - 1 - (i - next_depth - 1) * 3;
551 pain_.line(x, yo_, x, h, LColor::depthbar);
554 pain_.fillRectangle(x, yo_, w, 2, LColor::depthbar);
556 pain_.fillRectangle(x, h, w, 2, LColor::depthbar);
561 int RowPainter::paintLengthMarker(string const & prefix, VSpace const & vsp, int start)
563 if (vsp.kind() == VSpace::NONE)
566 int const arrow_size = 4;
567 int const size = getLengthMarkerHeight(bv_, vsp);
568 int const end = start + size;
570 // the label to display (if any)
572 // y-values for top arrow
574 // y-values for bottom arrow
577 str = prefix + " (" + vsp.asLyXCommand() + ")";
579 if (vsp.kind() == VSpace::VFILL) {
583 // adding or removing space
584 bool const added = vsp.kind() != VSpace::LENGTH ||
585 vsp.length().len().value() > 0.0;
586 ty1 = added ? (start + arrow_size) : start;
587 ty2 = added ? start : (start + arrow_size);
588 by1 = added ? (end - arrow_size) : end;
589 by2 = added ? end : (end - arrow_size);
592 int const leftx = int(xo_) + leftMargin();
593 int const midx = leftx + arrow_size;
594 int const rightx = midx + arrow_size;
602 font.setColor(LColor::added_space);
605 font_metrics::rectText(str, font, w, a, d);
607 pain_.rectText(leftx + 2 * arrow_size + 5,
608 start + ((end - start) / 2) + d,
610 LColor::none, LColor::none);
613 pain_.line(leftx, ty1, midx, ty2, LColor::added_space);
614 pain_.line(midx, ty2, rightx, ty1, LColor::added_space);
617 pain_.line(leftx, by1, midx, by2, LColor::added_space);
618 pain_.line(midx, by2, rightx, by1, LColor::added_space);
621 pain_.line(midx, ty2, midx, by2, LColor::added_space);
627 int RowPainter::paintPageBreak(string const & label, int y)
630 pb_font.setColor(LColor::pagebreak);
636 font_metrics::rectText(label, pb_font, w, a, d);
638 int const text_start = int(xo_ + (width_ - w) / 2);
639 int const text_end = text_start + w;
641 pain_.rectText(text_start, y + d, label, pb_font, LColor::none, LColor::none);
643 pain_.line(int(xo_), y, text_start, y,
644 LColor::pagebreak, Painter::line_onoffdash);
645 pain_.line(text_end, y, int(xo_ + width_), y,
646 LColor::pagebreak, Painter::line_onoffdash);
648 return 3 * defaultRowHeight();
652 int RowPainter::paintAppendixStart(int y)
655 pb_font.setColor(LColor::appendix);
658 string const label = _("Appendix");
662 font_metrics::rectText(label, pb_font, w, a, d);
664 int const text_start = int(xo_ + (width_ - w) / 2);
665 int const text_end = text_start + w;
667 pain_.rectText(text_start, y + d, label, pb_font, LColor::none, LColor::none);
669 pain_.line(int(xo_ + 1), y, text_start, y, LColor::appendix);
670 pain_.line(text_end, y, int(xo_ + width_ - 2), y, LColor::appendix);
672 return 3 * defaultRowHeight();
676 void RowPainter::paintFirst()
678 ParagraphParameters const & parparams = pit_->params();
682 // start of appendix?
683 if (parparams.startOfAppendix())
684 y_top += paintAppendixStart(yo_ + y_top + 2 * defaultRowHeight());
687 if (row_ == text_.firstRow() && !text_.isInInset())
688 y_top += PAPER_MARGIN;
690 // draw a top pagebreak
691 if (parparams.pagebreakTop())
692 y_top += paintPageBreak(_("Page Break (top)"),
693 yo_ + y_top + 2 * defaultRowHeight());
695 // draw the additional space if needed:
696 y_top += paintLengthMarker(_("Space above"), parparams.spaceTop(),
699 Buffer const & buffer = *bv_.buffer();
701 LyXLayout_ptr const & layout = pit_->layout();
703 if (buffer.params().paragraph_separation == BufferParams::PARSEP_SKIP) {
704 if (pit_ != text_.ownerParagraphs().begin()) {
705 if (layout->latextype == LATEX_PARAGRAPH
706 && !pit_->getDepth()) {
707 y_top += buffer.params().getDefSkip().inPixels(bv_);
709 LyXLayout_ptr const & playout =
710 boost::prior(pit_)->layout();
711 if (playout->latextype == LATEX_PARAGRAPH
712 && !boost::prior(pit_)->getDepth()) {
713 // is it right to use defskip here, too? (AS)
714 y_top += buffer.params().getDefSkip().inPixels(bv_);
720 int const ww = bv_.workWidth();
723 if (parparams.lineTop()) {
724 int const asc = font_metrics::ascent('x', getFont(0));
728 int const w = (text_.isInInset() ? text_.inset_owner->width() : ww);
729 int const xp = static_cast<int>(text_.isInInset() ? xo_ : 0);
730 pain_.line(xp, yo_ + y_top, xp + w, yo_ + y_top,
731 LColor::topline, Painter::line_solid,
732 Painter::line_thick);
737 bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params());
739 // should we print a label?
740 if (layout->labeltype >= LABEL_STATIC
741 && (layout->labeltype != LABEL_STATIC
742 || layout->latextype != LATEX_ENVIRONMENT
743 || isFirstInSequence(pit_, text_.ownerParagraphs()))) {
745 LyXFont font = getLabelFont();
746 if (!pit_->getLabelstring().empty()) {
748 string const str = pit_->getLabelstring();
750 // this is special code for the chapter layout. This is
751 // printed in an extra row and has a pagebreak at
753 if (layout->counter == "chapter") {
754 if (buffer.params().secnumdepth >= 0) {
755 float spacing_val = 1.0;
756 if (!parparams.spacing().isDefault()) {
757 spacing_val = parparams.spacing().getValue();
759 spacing_val = buffer.params().spacing().getValue();
763 int(font_metrics::maxDescent(font) * layout->spacing.getValue() * spacing_val)
764 + int(layout->parsep) * defaultRowHeight();
767 x = ww - leftMargin() -
768 font_metrics::width(str, font);
772 yo_ + row_->baseline() -
773 row_->ascent_of_text() - maxdesc,
778 x = ww - leftMargin()
779 + font_metrics::width(layout->labelsep, font);
781 x = x_ - font_metrics::width(layout->labelsep, font)
782 - font_metrics::width(str, font);
785 pain_.text(int(x), yo_ + row_->baseline(), str, font);
789 // the labels at the top of an environment.
790 // More or less for bibliography
791 } else if (isFirstInSequence(pit_, text_.ownerParagraphs()) &&
792 (layout->labeltype == LABEL_TOP_ENVIRONMENT ||
793 layout->labeltype == LABEL_BIBLIO ||
794 layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)) {
795 LyXFont font = getLabelFont();
796 if (!pit_->getLabelstring().empty()) {
797 string const str = pit_->getLabelstring();
798 float spacing_val = 1.0;
799 if (!parparams.spacing().isDefault()) {
800 spacing_val = parparams.spacing().getValue();
802 spacing_val = buffer.params().spacing().getValue();
806 int(font_metrics::maxDescent(font) * layout->spacing.getValue() * spacing_val
807 + (layout->labelbottomsep * defaultRowHeight()));
810 if (layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
811 x = ((is_rtl ? leftMargin() : x_)
812 + ww - text_.rightMargin(pit_, *bv_.buffer(), *row_)) / 2;
813 x -= font_metrics::width(str, font) / 2;
815 x = ww - leftMargin() -
816 font_metrics::width(str, font);
819 yo_ + row_->baseline() - row_->ascent_of_text() - maxdesc,
826 void RowPainter::paintLast()
828 ParagraphParameters const & parparams = pit_->params();
829 int y_bottom = row_->height() - 1;
832 if (row_ == text_.lastRow() && !text_.isInInset())
833 y_bottom -= PAPER_MARGIN;
835 int const ww = bv_.workWidth();
837 // draw a bottom pagebreak
838 if (parparams.pagebreakBottom()) {
839 y_bottom -= paintPageBreak(_("Page Break (bottom)"),
840 yo_ + y_bottom - 2 * defaultRowHeight());
843 // draw the additional space if needed:
844 int const height = getLengthMarkerHeight(bv_, parparams.spaceBottom());
845 y_bottom -= paintLengthMarker(_("Space below"), parparams.spaceBottom(),
846 yo_ + y_bottom - height);
848 // draw a bottom line
849 if (parparams.lineBottom()) {
850 int const asc = font_metrics::ascent('x',
851 getFont(max(pos_type(0), pit_->size() - 1)));
855 int const w = text_.isInInset() ? text_.inset_owner->width() : ww;
856 int const xp = int(text_.isInInset() ? xo_ : 0);
857 int const y = yo_ + y_bottom;
858 pain_.line(xp, y, xp + w, y, LColor::topline, Painter::line_solid,
859 Painter::line_thick);
864 bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params());
865 int const endlabel = getEndLabel(pit_, text_.ownerParagraphs());
870 case END_LABEL_FILLED_BOX:
872 LyXFont const font = getLabelFont();
873 int const size = int(0.75 * font_metrics::maxAscent(font));
874 int const y = (yo_ + row_->baseline()) - size;
875 int x = is_rtl ? LEFT_MARGIN : ww - PAPER_MARGIN - size;
877 if (row_->fill() <= size)
878 x += (size - row_->fill() + 1) * (is_rtl ? -1 : 1);
880 if (endlabel == END_LABEL_BOX)
881 pain_.rectangle(x, y, size, size, LColor::eolmarker);
883 pain_.fillRectangle(x, y, size, size, LColor::eolmarker);
886 case END_LABEL_STATIC:
888 LyXFont font = getLabelFont();
889 string const & str = pit_->layout()->endlabelstring();
890 double const x = is_rtl ?
891 x_ - font_metrics::width(str, font)
892 : ww - text_.rightMargin(pit_, *bv_.buffer(), *row_) - row_->fill();
893 pain_.text(int(x), yo_ + row_->baseline(), str, font);
896 case END_LABEL_NO_LABEL:
902 void RowPainter::paintText()
904 pos_type const last = lastPos(*pit_, row_);
905 pos_type body_pos = pit_->beginningOfBody();
907 (body_pos - 1 > last || !pit_->isLineSeparator(body_pos - 1))) {
911 LyXLayout_ptr const & layout = pit_->layout();
913 bool running_strikeout = false;
914 bool is_struckout = false;
915 int last_strikeout_x = 0;
917 pos_type vpos = row_->pos();
918 while (vpos <= last) {
919 if (x_ > bv_.workWidth())
921 pos_type pos = text_.vis2log(vpos);
923 if (pos >= pit_->size()) {
928 if (x_ + singleWidth(pos) < 0) {
929 x_ += singleWidth(pos);
934 is_struckout = isDeletedText(*pit_, pos);
936 if (is_struckout && !running_strikeout) {
937 running_strikeout = true;
938 last_strikeout_x = int(x_);
941 bool const highly_editable_inset = pit_->isInset(pos)
942 && isHighlyEditableInset(pit_->getInset(pos));
944 // if we reach the end of a struck out range, paint it
945 // we also don't paint across things like tables
946 if (running_strikeout && (highly_editable_inset || !is_struckout)) {
947 int const middle = yo_ + row_->top_of_text()
948 + (row_->baseline() - row_->top_of_text()) / 2;
949 pain_.line(last_strikeout_x, middle, int(x_), middle,
950 LColor::strikeout, Painter::line_solid, Painter::line_thin);
951 running_strikeout = false;
954 if (body_pos > 0 && pos == body_pos - 1) {
955 int const lwidth = font_metrics::width(layout->labelsep,
958 x_ += label_hfill_ + lwidth - singleWidth(body_pos - 1);
961 if (pit_->isHfill(pos)) {
964 int const y0 = yo_ + row_->baseline();
965 int const y1 = y0 - defaultRowHeight() / 2;
967 pain_.line(int(x_), y1, int(x_), y0, LColor::added_space);
969 if (hfillExpansion(*pit_, row_, pos)) {
970 int const y2 = (y0 + y1) / 2;
972 if (pos >= body_pos) {
973 pain_.line(int(x_), y2, int(x_ + hfill_), y2,
975 Painter::line_onoffdash);
978 pain_.line(int(x_), y2, int(x_ + label_hfill_), y2,
980 Painter::line_onoffdash);
983 pain_.line(int(x_), y1, int(x_), y0, LColor::added_space);
987 } else if (pit_->isSeparator(pos)) {
988 x_ += singleWidth(pos);
997 // if we reach the end of a struck out range, paint it
998 if (running_strikeout) {
999 int const middle = yo_ + row_->top_of_text()
1000 + ((row_->baseline() - row_->top_of_text()) / 2);
1001 pain_.line(last_strikeout_x, middle, int(x_), middle,
1002 LColor::strikeout, Painter::line_solid, Painter::line_thin);
1003 running_strikeout = false;
1008 void RowPainter::paint()
1010 width_ = text_.workWidth();
1012 separator_ = row_->fill_separator();
1013 hfill_ = row_->fill_hfill();
1014 label_hfill_ = row_->fill_label_hfill();
1016 // FIXME: what is this fixing ?
1017 if (text_.isInInset() && x_ < 0)
1021 // If we're *not* at the top-level of rows, then the
1022 // background has already been cleared.
1023 if (&text_ == bv_.text)
1026 // paint the selection background
1027 if (text_.selection.set())
1030 // vertical lines for appendix
1033 // environment depth brackets
1039 if (row_->isParStart())
1042 if (isParEnd(*pit_, row_))
1050 int paintRows(BufferView const & bv, LyXText const & text,
1051 ParagraphList::iterator pit, RowList::iterator rit,
1052 int xo, int y, int yf, int yo)
1054 //lyxerr << " paintRows: rit: " << &*rit << endl;
1055 //const_cast<LyXText&>(text).updateRowPositions();
1056 int const yy = yf - y;
1057 int const y2 = bv.painter().paperHeight();
1059 ParagraphList::iterator end = text.ownerParagraphs().end();
1060 bool active = false;
1062 for ( ; pit != end; ++pit) {
1063 RowList::iterator row = pit->rows.begin();
1064 RowList::iterator rend = pit->rows.end();
1066 for ( ; row != rend; ++row) {
1070 RowPainter painter(bv, text, pit, row, y + yo, xo, y + bv.top_y());
1076 //lyxerr << " paintRows: row: " << &*row << " ignored" << endl;
1087 int paintText(BufferView & bv)
1089 int const topy = bv.top_y();
1090 ParagraphList::iterator pit;
1091 RowList::iterator rit = bv.text->getRowNearY(topy, pit);
1092 int y = rit->y() - topy;
1093 return paintRows(bv, *bv.text, pit, rit, 0, y, y, 0);
1097 void paintTextInset(BufferView & bv, LyXText & text, int x, int baseline)
1099 RowList::iterator rit = text.firstRow();
1100 RowList::iterator end = text.endRow();
1101 ParagraphList::iterator pit = text.ownerParagraphs().begin();
1103 int y_offset = baseline - rit->ascent_of_text();
1105 while (rit != end && y + rit->height() <= 0) {
1107 text.nextRow(pit, rit);
1110 paintRows(bv, text, pit, rit, x, 0, y, y);
1112 paintRows(bv, text, pit, rit, x, 0, y_offset, y_offset);
1116 int getLengthMarkerHeight(BufferView const & bv, VSpace const & vsp)
1118 if (vsp.kind() == VSpace::NONE)
1121 int const arrow_size = 4;
1122 int const space_size = vsp.inPixels(bv);
1126 int const min_size = max(3 * arrow_size,
1127 font_metrics::maxAscent(font)
1128 + font_metrics::maxDescent(font));
1130 if (vsp.length().len().value() < 0.0)
1133 return max(min_size, space_size);