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/screen.h"
16 #include "frontends/font_metrics.h"
17 #include "support/LAssert.h"
18 #include "paragraph.h"
19 #include "paragraph_funcs.h"
20 #include "support/textutils.h"
22 #include "insets/insettext.h"
23 #include "ParagraphParameters.h"
25 #include "BufferView.h"
32 #include "rowpainter.h"
34 #include "lyxrow_funcs.h"
35 #include "metricsinfo.h"
39 using namespace lyx::support;
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 RowList::iterator rit, int y_offset, int x_offset, int y);
70 // paint various parts
71 void paintBackground();
72 void paintSelection();
75 void paintChangeBar();
78 void paintForeignMark(double orig_x, LyXFont const & orig_font);
79 void paintHebrewComposeChar(lyx::pos_type & vpos);
80 void paintArabicComposeChar(lyx::pos_type & vpos);
81 void paintChars(lyx::pos_type & vpos, bool hebrew, bool arabic);
82 int paintPageBreak(string const & label, int y);
83 int paintAppendixStart(int y);
84 int paintLengthMarker(string const & prefix, VSpace const & vsp, int start);
86 void paintFromPos(lyx::pos_type & vpos);
87 void paintInset(lyx::pos_type const pos);
89 /// return left margin
90 int leftMargin() const;
92 /// return the font at the given pos
93 LyXFont const getFont(lyx::pos_type pos) const;
95 /// return the label font for this row
96 LyXFont const getLabelFont() const;
98 char const transformChar(char c, lyx::pos_type pos) const;
100 /// return pixel width for the given pos
101 int singleWidth(lyx::pos_type pos) const;
102 int singleWidth(lyx::pos_type pos, char c) const;
104 /// bufferview to paint on
105 BufferView const & bv_;
110 /// LyXText for the row
111 LyXText const & text_;
114 RowList::iterator row_;
117 mutable ParagraphList::iterator pit_;
131 RowPainter::RowPainter(BufferView const & bv, LyXText const & text,
132 RowList::iterator rit,
133 int y_offset, int x_offset, int y)
134 : bv_(bv), pain_(bv_.painter()), text_(text), row_(rit),
136 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 return text_.singleWidth(pit_, pos, c);
159 LyXFont const RowPainter::getLabelFont() const
161 return text_.getLabelFont(pit_);
165 char const RowPainter::transformChar(char c, lyx::pos_type pos) const
167 return text_.transformChar(c, *pit_, pos);
171 int RowPainter::leftMargin() const
173 return text_.leftMargin(*row_);
177 void RowPainter::paintInset(pos_type const pos)
179 InsetOld * inset = const_cast<InsetOld*>(pit_->getInset(pos));
183 PainterInfo pi(perv(bv_));
184 pi.base.font = getFont(pos);
185 inset->draw(pi, int(x_), yo_ + row_->baseline());
186 x_ += inset->width();
190 void RowPainter::paintHebrewComposeChar(pos_type & vpos)
192 pos_type pos = text_.vis2log(vpos);
197 char c = pit_->getChar(pos);
201 LyXFont const & font = getFont(pos);
202 int const width = font_metrics::width(c, font);
205 for (pos_type i = pos - 1; i >= 0; --i) {
206 c = pit_->getChar(i);
207 if (!Encodings::IsComposeChar_hebrew(c)) {
208 if (IsPrintableNonspace(c)) {
212 dx = (c == 'ø' || c == 'ã')
214 : (width2 - width) / 2;
221 pain_.text(int(x_) + dx, yo_ + row_->baseline(), str, font);
225 void RowPainter::paintArabicComposeChar(pos_type & vpos)
227 pos_type pos = text_.vis2log(vpos);
231 char c = pit_->getChar(pos);
232 c = transformChar(c, pos);
236 LyXFont const & font = getFont(pos);
237 int const width = font_metrics::width(c, font);
240 for (pos_type i = pos - 1; i >= 0; --i) {
241 c = pit_->getChar(i);
242 if (!Encodings::IsComposeChar_arabic(c)) {
243 if (IsPrintableNonspace(c)) {
246 dx = (width2 - width) / 2;
252 pain_.text(int(x_) + dx, yo_ + row_->baseline(), str, font);
256 void RowPainter::paintChars(pos_type & vpos, bool hebrew, bool arabic)
258 pos_type pos = text_.vis2log(vpos);
259 pos_type const last = lastPrintablePos(text_, row_);
260 LyXFont orig_font = getFont(pos);
264 str += pit_->getChar(pos);
266 unsigned char c = str[0];
267 str[0] = transformChar(c, pos);
270 bool prev_struckout(isDeletedText(*pit_, pos));
271 bool prev_newtext(isInsertedText(*pit_, pos));
275 // collect as much similar chars as we can
276 while (vpos <= last && (pos = text_.vis2log(vpos)) >= 0) {
277 char c = pit_->getChar(pos);
279 if (!IsPrintableNonspace(c))
282 if (prev_struckout != isDeletedText(*pit_, pos))
285 if (prev_newtext != isInsertedText(*pit_, pos))
288 if (arabic && Encodings::IsComposeChar_arabic(c))
290 if (hebrew && Encodings::IsComposeChar_hebrew(c))
293 if (orig_font != getFont(pos))
297 c = transformChar(c, pos);
302 if (prev_struckout) {
303 orig_font.setColor(LColor::strikeout);
304 } else if (prev_newtext) {
305 orig_font.setColor(LColor::newtext);
308 // Draw text and set the new x position
309 //lyxerr << "paint row: yo_ " << yo_ << " baseline: " << row_->baseline()
311 pain_.text(int(x_), yo_ + row_->baseline(), str, orig_font);
312 x_ += font_metrics::width(str, orig_font);
316 void RowPainter::paintForeignMark(double orig_x, LyXFont const & orig_font)
318 if (!lyxrc.mark_foreign_language)
320 if (orig_font.language() == latex_language)
322 if (orig_font.language() == bv_.buffer()->params.language)
325 int const y = yo_ + row_->baseline() + 1;
326 pain_.line(int(orig_x), y, int(x_), y, LColor::language);
330 void RowPainter::paintFromPos(pos_type & vpos)
332 pos_type const pos = text_.vis2log(vpos);
334 LyXFont const & orig_font = getFont(pos);
336 double const orig_x = x_;
338 char const c = pit_->getChar(pos);
340 if (IsInsetChar(c)) {
343 paintForeignMark(orig_x, orig_font);
347 // usual characters, no insets
349 // special case languages
350 bool const hebrew = (orig_font.language()->lang() == "hebrew");
352 orig_font.language()->lang() == "arabic" &&
353 (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
354 lyxrc.font_norm_type == LyXRC::ISO_10646_1);
356 // draw as many chars as we can
357 if ((!hebrew && !arabic)
358 || (hebrew && !Encodings::IsComposeChar_hebrew(c))
359 || (arabic && !Encodings::IsComposeChar_arabic(c))) {
360 paintChars(vpos, hebrew, arabic);
362 paintHebrewComposeChar(vpos);
364 paintArabicComposeChar(vpos);
367 paintForeignMark(orig_x, orig_font);
373 void RowPainter::paintBackground()
375 int const x = int(xo_);
376 int const y = yo_ < 0 ? 0 : yo_;
377 int const h = yo_ < 0 ? row_->height() + yo_ : row_->height();
378 pain_.fillRectangle(x, y, width_, h, text_.backgroundColor());
382 void RowPainter::paintSelection()
384 bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params);
386 // the current selection
387 int const startx = text_.selection.start.x();
388 int const endx = text_.selection.end.x();
389 int const starty = text_.selection.start.y();
390 int const endy = text_.selection.end.y();
391 RowList::iterator startrow = text_.getRow(text_.selection.start);
392 RowList::iterator endrow = text_.getRow(text_.selection.end);
394 if (text_.bidi_same_direction) {
398 int h = row_->height();
400 if (startrow == row_ && endrow == row_) {
402 x = int(xo_) + startx;
404 pain_.fillRectangle(x, y, w, h, LColor::selection);
408 pain_.fillRectangle(x, y, w, h, LColor::selection);
410 } else if (startrow == row_) {
411 int const x = is_rtl ? int(xo_) : int(xo_ + startx);
412 int const w = is_rtl ? startx : (width_ - startx);
413 pain_.fillRectangle(x, y, w, h, LColor::selection);
414 } else if (endrow == row_) {
415 int const x = is_rtl ? int(xo_ + endx) : int(xo_);
416 int const w = is_rtl ? (width_ - endx) : endx;
417 pain_.fillRectangle(x, y, w, h, LColor::selection);
418 } else if (y_ > starty && y_ < endy) {
419 pain_.fillRectangle(int(xo_), y, width_, h, LColor::selection);
422 } else if (startrow != row_ && endrow != row_) {
423 if (y_ > starty && y_ < endy) {
425 int h = row_->height();
426 pain_.fillRectangle(int(xo_), yo_, w, h, LColor::selection);
431 if ((startrow != row_ && !is_rtl) || (endrow != row_ && is_rtl))
432 pain_.fillRectangle(int(xo_), yo_,
433 int(x_), row_->height(), LColor::selection);
435 pos_type const body_pos = pit_->beginningOfBody();
436 pos_type const last = lastPrintablePos(text_, row_);
439 for (pos_type vpos = row_->pos(); vpos <= last; ++vpos) {
440 pos_type pos = text_.vis2log(vpos);
441 double const old_tmpx = tmpx;
442 if (body_pos > 0 && pos == body_pos - 1) {
443 LyXLayout_ptr const & layout = pit_->layout();
444 LyXFont const lfont = getLabelFont();
446 tmpx += label_hfill_ + font_metrics::width(layout->labelsep, lfont);
448 if (pit_->isLineSeparator(body_pos - 1))
449 tmpx -= singleWidth(body_pos - 1);
452 if (hfillExpansion(text_, row_, pos)) {
453 tmpx += singleWidth(pos);
457 tmpx += label_hfill_;
460 else if (pit_->isSeparator(pos)) {
461 tmpx += singleWidth(pos);
465 tmpx += singleWidth(pos);
468 if ((startrow != row_ || text_.selection.start.pos() <= pos) &&
469 (endrow != row_ || pos < text_.selection.end.pos())) {
470 // Here we do not use x_ as xo_ was added to x_.
471 pain_.fillRectangle(int(old_tmpx), yo_,
472 int(tmpx - old_tmpx + 1),
473 row_->height(), LColor::selection);
477 if ((startrow != row_ && is_rtl) || (endrow != row_ && !is_rtl)) {
478 pain_.fillRectangle(int(xo_ + tmpx),
479 yo_, int(bv_.workWidth() - tmpx),
480 row_->height(), LColor::selection);
485 void RowPainter::paintChangeBar()
487 pos_type const start = row_->pos();
488 pos_type const end = lastPrintablePos(text_, row_);
490 if (!pit_->isChanged(start, end))
493 int const height = (boost::next(row_) != text_.rows().end()
494 ? row_->height() + boost::next(row_)->top_of_text()
497 pain_.fillRectangle(4, yo_, 5, height, LColor::changebar);
501 void RowPainter::paintAppendix()
503 if (!pit_->params().appendix())
506 // FIXME: can be just width_ ?
507 int const ww = bv_.workWidth();
511 if (pit_->params().startOfAppendix())
512 y += 2 * defaultRowHeight();
514 pain_.line(1, y, 1, yo_ + row_->height(), LColor::appendix);
515 pain_.line(ww - 2, y, ww - 2, yo_ + row_->height(), LColor::appendix);
519 void RowPainter::paintDepthBar()
521 Paragraph::depth_type const depth = pit_->getDepth();
526 Paragraph::depth_type prev_depth = 0;
527 if (row_ != text_.rows().begin())
528 prev_depth = boost::prior(row_)->par()->getDepth();
529 Paragraph::depth_type next_depth = 0;
531 RowList::iterator next_row = boost::next(row_);
532 if (next_row != text_.rows().end())
533 next_depth = next_row->par()->getDepth();
535 for (Paragraph::depth_type i = 1; i <= depth; ++i) {
536 int const w = PAPER_MARGIN / 5;
537 int x = int(w * i + xo_);
538 // only consider the changebar space if we're drawing outer left
540 x += CHANGEBAR_MARGIN;
541 int const h = yo_ + row_->height() - 1 - (i - next_depth - 1) * 3;
543 pain_.line(x, yo_, x, h, LColor::depthbar);
546 pain_.fillRectangle(x, yo_, w, 2, LColor::depthbar);
548 pain_.fillRectangle(x, h, w, 2, LColor::depthbar);
553 int RowPainter::paintLengthMarker(string const & prefix, VSpace const & vsp, int start)
555 if (vsp.kind() == VSpace::NONE)
558 int const arrow_size = 4;
559 int const size = getLengthMarkerHeight(bv_, vsp);
560 int const end = start + size;
562 // the label to display (if any)
564 // y-values for top arrow
566 // y-values for bottom arrow
569 str = prefix + " (" + vsp.asLyXCommand() + ")";
571 if (vsp.kind() == VSpace::VFILL) {
575 // adding or removing space
576 bool const added = vsp.kind() != VSpace::LENGTH ||
577 vsp.length().len().value() > 0.0;
578 ty1 = added ? (start + arrow_size) : start;
579 ty2 = added ? start : (start + arrow_size);
580 by1 = added ? (end - arrow_size) : end;
581 by2 = added ? end : (end - arrow_size);
584 int const leftx = int(xo_) + leftMargin();
585 int const midx = leftx + arrow_size;
586 int const rightx = midx + arrow_size;
594 font.setColor(LColor::added_space).decSize().decSize();
595 font_metrics::rectText(str, font, w, a, d);
597 pain_.rectText(leftx + 2 * arrow_size + 5,
598 start + ((end - start) / 2) + d,
602 pain_.line(leftx, ty1, midx, ty2, LColor::added_space);
603 pain_.line(midx, ty2, rightx, ty1, LColor::added_space);
606 pain_.line(leftx, by1, midx, by2, LColor::added_space);
607 pain_.line(midx, by2, rightx, by1, LColor::added_space);
610 pain_.line(midx, ty2, midx, by2, LColor::added_space);
616 int RowPainter::paintPageBreak(string const & label, int y)
619 pb_font.setColor(LColor::pagebreak).decSize();
624 font_metrics::rectText(label, pb_font, w, a, d);
626 int const text_start = int(xo_ + (width_ - w) / 2);
627 int const text_end = text_start + w;
629 pain_.rectText(text_start, y + d, label, pb_font);
631 pain_.line(int(xo_), y, text_start, y,
632 LColor::pagebreak, Painter::line_onoffdash);
633 pain_.line(text_end, y, int(xo_ + width_), y,
634 LColor::pagebreak, Painter::line_onoffdash);
636 return 3 * defaultRowHeight();
640 int RowPainter::paintAppendixStart(int y)
643 pb_font.setColor(LColor::appendix).decSize();
645 string const label = _("Appendix");
649 font_metrics::rectText(label, pb_font, w, a, d);
651 int const text_start = int(xo_ + (width_ - w) / 2);
652 int const text_end = text_start + w;
654 pain_.rectText(text_start, y + d, label, pb_font);
656 pain_.line(int(xo_ + 1), y, text_start, y, LColor::appendix);
657 pain_.line(text_end, y, int(xo_ + width_ - 2), y, LColor::appendix);
659 return 3 * defaultRowHeight();
663 void RowPainter::paintFirst()
665 ParagraphParameters const & parparams = pit_->params();
669 // start of appendix?
670 if (parparams.startOfAppendix())
671 y_top += paintAppendixStart(yo_ + y_top + 2 * defaultRowHeight());
674 if (row_ == text_.rows().begin() && !text_.isInInset())
675 y_top += PAPER_MARGIN;
677 // draw a top pagebreak
678 if (parparams.pagebreakTop())
679 y_top += paintPageBreak(_("Page Break (top)"),
680 yo_ + y_top + 2 * defaultRowHeight());
682 // draw the additional space if needed:
683 y_top += paintLengthMarker(_("Space above"), parparams.spaceTop(),
686 Buffer const * buffer = bv_.buffer();
688 LyXLayout_ptr const & layout = pit_->layout();
690 if (buffer->params.paragraph_separation == BufferParams::PARSEP_SKIP) {
691 if (pit_ != text_.ownerParagraphs().begin()) {
692 if (layout->latextype == LATEX_PARAGRAPH
693 && !pit_->getDepth()) {
694 y_top += buffer->params.getDefSkip().inPixels(bv_);
696 LyXLayout_ptr const & playout =
697 boost::prior(pit_)->layout();
698 if (playout->latextype == LATEX_PARAGRAPH
699 && !boost::prior(pit_)->getDepth()) {
700 // is it right to use defskip here, too? (AS)
701 y_top += buffer->params.getDefSkip().inPixels(bv_);
707 int const ww = bv_.workWidth();
710 if (parparams.lineTop()) {
711 int const asc = font_metrics::ascent('x', getFont(0));
715 int const w = (text_.isInInset() ? text_.inset_owner->width() : ww);
716 int const xp = static_cast<int>(text_.isInInset() ? xo_ : 0);
717 pain_.line(xp, yo_ + y_top, xp + w, yo_ + y_top,
718 LColor::topline, Painter::line_solid,
719 Painter::line_thick);
724 bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params);
726 // should we print a label?
727 if (layout->labeltype >= LABEL_STATIC
728 && (layout->labeltype != LABEL_STATIC
729 || layout->latextype != LATEX_ENVIRONMENT
730 || isFirstInSequence(pit_, text_.ownerParagraphs()))) {
732 LyXFont font = getLabelFont();
733 if (!pit_->getLabelstring().empty()) {
735 string const str = pit_->getLabelstring();
737 // this is special code for the chapter layout. This is
738 // printed in an extra row and has a pagebreak at
740 if (layout->labeltype == LABEL_COUNTER_CHAPTER) {
741 if (buffer->params.secnumdepth >= 0) {
742 float spacing_val = 1.0;
743 if (!parparams.spacing().isDefault()) {
744 spacing_val = parparams.spacing().getValue();
746 spacing_val = buffer->params.spacing.getValue();
750 int(font_metrics::maxDescent(font) * layout->spacing.getValue() * spacing_val)
751 + int(layout->parsep) * defaultRowHeight();
754 x = ww - leftMargin() -
755 font_metrics::width(str, font);
759 yo_ + row_->baseline() -
760 row_->ascent_of_text() - maxdesc,
765 x = ww - leftMargin()
766 + font_metrics::width(layout->labelsep, font);
768 x = x_ - font_metrics::width(layout->labelsep, font)
769 - font_metrics::width(str, font);
772 pain_.text(int(x), yo_ + row_->baseline(), str, font);
776 // the labels at the top of an environment.
777 // More or less for bibliography
778 } else if (isFirstInSequence(pit_, text_.ownerParagraphs()) &&
779 (layout->labeltype == LABEL_TOP_ENVIRONMENT ||
780 layout->labeltype == LABEL_BIBLIO ||
781 layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)) {
782 LyXFont font = getLabelFont();
783 if (!pit_->getLabelstring().empty()) {
784 string const str = pit_->getLabelstring();
785 float spacing_val = 1.0;
786 if (!parparams.spacing().isDefault()) {
787 spacing_val = parparams.spacing().getValue();
789 spacing_val = buffer->params.spacing.getValue();
793 int(font_metrics::maxDescent(font) * layout->spacing.getValue() * spacing_val
794 + (layout->labelbottomsep * defaultRowHeight()));
797 if (layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
798 x = ((is_rtl ? leftMargin() : x_)
799 + ww - text_.rightMargin(*bv_.buffer(), *row_)) / 2;
800 x -= font_metrics::width(str, font) / 2;
802 x = ww - leftMargin() -
803 font_metrics::width(str, font);
806 yo_ + row_->baseline() - row_->ascent_of_text() - maxdesc,
813 void RowPainter::paintLast()
815 ParagraphParameters const & parparams = pit_->params();
816 int y_bottom = row_->height() - 1;
819 if (boost::next(row_) == text_.rows().end() && !text_.isInInset())
820 y_bottom -= PAPER_MARGIN;
822 int const ww = bv_.workWidth();
824 // draw a bottom pagebreak
825 if (parparams.pagebreakBottom()) {
826 y_bottom -= paintPageBreak(_("Page Break (bottom)"),
827 yo_ + y_bottom - 2 * defaultRowHeight());
830 // draw the additional space if needed:
831 int const height = getLengthMarkerHeight(bv_, parparams.spaceBottom());
832 y_bottom -= paintLengthMarker(_("Space below"), parparams.spaceBottom(),
833 yo_ + y_bottom - height);
835 // draw a bottom line
836 if (parparams.lineBottom()) {
837 int const asc = font_metrics::ascent('x',
838 getFont(max(pos_type(0), pit_->size() - 1)));
842 int const w = text_.isInInset() ? text_.inset_owner->width() : ww;
843 int const xp = int(text_.isInInset() ? xo_ : 0);
844 int const y = yo_ + y_bottom;
845 pain_.line(xp, y, xp + w, y, LColor::topline, Painter::line_solid,
846 Painter::line_thick);
851 bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params);
852 int const endlabel = getEndLabel(pit_, text_.ownerParagraphs());
857 case END_LABEL_FILLED_BOX:
859 LyXFont const font = getLabelFont();
860 int const size = int(0.75 * font_metrics::maxAscent(font));
861 int const y = (yo_ + row_->baseline()) - size;
862 int x = is_rtl ? LEFT_MARGIN : ww - PAPER_MARGIN - size;
864 if (row_->fill() <= size)
865 x += (size - row_->fill() + 1) * (is_rtl ? -1 : 1);
867 if (endlabel == END_LABEL_BOX)
868 pain_.rectangle(x, y, size, size, LColor::eolmarker);
870 pain_.fillRectangle(x, y, size, size, LColor::eolmarker);
873 case END_LABEL_STATIC:
875 LyXFont font = getLabelFont();
876 string const & str = pit_->layout()->endlabelstring();
877 double const x = is_rtl ?
878 x_ - font_metrics::width(str, font)
879 : ww - text_.rightMargin(*bv_.buffer(), *row_) - row_->fill();
880 pain_.text(int(x), yo_ + row_->baseline(), str, font);
883 case END_LABEL_NO_LABEL:
889 void RowPainter::paintText()
891 pos_type const last = lastPrintablePos(text_, row_);
892 pos_type body_pos = pit_->beginningOfBody();
894 (body_pos - 1 > last || !pit_->isLineSeparator(body_pos - 1))) {
898 LyXLayout_ptr const & layout = pit_->layout();
900 bool running_strikeout = false;
901 bool is_struckout = false;
902 int last_strikeout_x = 0;
904 pos_type vpos = row_->pos();
905 while (vpos <= last) {
906 if (x_ > bv_.workWidth())
908 pos_type pos = text_.vis2log(vpos);
910 if (pos >= pit_->size()) {
915 if (x_ + singleWidth(pos) < 0) {
916 x_ += singleWidth(pos);
921 is_struckout = isDeletedText(*pit_, pos);
923 if (is_struckout && !running_strikeout) {
924 running_strikeout = true;
925 last_strikeout_x = int(x_);
928 bool const highly_editable_inset = pit_->isInset(pos)
929 && isHighlyEditableInset(pit_->getInset(pos));
931 // if we reach the end of a struck out range, paint it
932 // we also don't paint across things like tables
933 if (running_strikeout && (highly_editable_inset || !is_struckout)) {
934 int const middle = yo_ + row_->top_of_text()
935 + (row_->baseline() - row_->top_of_text()) / 2;
936 pain_.line(last_strikeout_x, middle, int(x_), middle,
937 LColor::strikeout, Painter::line_solid, Painter::line_thin);
938 running_strikeout = false;
941 if (body_pos > 0 && pos == body_pos - 1) {
942 int const lwidth = font_metrics::width(layout->labelsep,
945 x_ += label_hfill_ + lwidth - singleWidth(body_pos - 1);
948 if (pit_->isHfill(pos)) {
951 int const y0 = yo_ + row_->baseline();
952 int const y1 = y0 - defaultRowHeight() / 2;
954 pain_.line(int(x_), y1, int(x_), y0, LColor::added_space);
956 if (hfillExpansion(text_, row_, pos)) {
957 int const y2 = (y0 + y1) / 2;
959 if (pos >= body_pos) {
960 pain_.line(int(x_), y2, int(x_ + hfill_), y2,
962 Painter::line_onoffdash);
965 pain_.line(int(x_), y2, int(x_ + label_hfill_), y2,
967 Painter::line_onoffdash);
970 pain_.line(int(x_), y1, int(x_), y0, LColor::added_space);
974 } else if (pit_->isSeparator(pos)) {
975 x_ += singleWidth(pos);
984 // if we reach the end of a struck out range, paint it
985 if (running_strikeout) {
986 int const middle = yo_ + row_->top_of_text()
987 + ((row_->baseline() - row_->top_of_text()) / 2);
988 pain_.line(last_strikeout_x, middle, int(x_), middle,
989 LColor::strikeout, Painter::line_solid, Painter::line_thin);
990 running_strikeout = false;
995 void RowPainter::paint()
997 width_ = text_.workWidth();
999 // FIXME: must be a cleaner way here. Aren't these calculations
1000 // belonging to row metrics ?
1001 text_.prepareToPrint(row_, x_, separator_, hfill_, label_hfill_);
1003 // FIXME: what is this fixing ?
1004 if (text_.isInInset() && x_ < 0)
1008 // If we're *not* at the top-level of rows, then the
1009 // background has already been cleared.
1010 if (&text_ == bv_.text)
1013 // paint the selection background
1014 if (text_.selection.set())
1017 // vertical lines for appendix
1020 // environment depth brackets
1026 if (row_->isParStart())
1029 if (isParEnd(text_, row_))
1040 int getLengthMarkerHeight(BufferView const & bv, VSpace const & vsp)
1042 if (vsp.kind() == VSpace::NONE)
1045 int const arrow_size = 4;
1046 int const space_size = vsp.inPixels(bv);
1050 int const min_size = max(3 * arrow_size,
1051 font_metrics::maxAscent(font)
1052 + font_metrics::maxDescent(font));
1054 if (vsp.length().len().value() < 0.0)
1057 return max(min_size, space_size);
1061 void paintRows(BufferView const & bv, LyXText const & text,
1062 RowList::iterator rit, int y_offset, int x_offset, int y)
1064 // fix up missing metrics() call for main LyXText
1065 // calling metrics() directly is (a) slow and (b) crashs
1066 if (&text == bv.text) {
1068 // make sure all insets are updated
1069 ParagraphList::iterator pit = text.ownerParagraphs().begin();
1070 ParagraphList::iterator end = text.ownerParagraphs().end();
1072 // compute inset metrics
1073 for (; pit != end; ++pit) {
1074 InsetList & insetList = pit->insetlist;
1075 InsetList::iterator ii = insetList.begin();
1076 InsetList::iterator iend = insetList.end();
1077 for (; ii != iend; ++ii) {
1080 MetricsInfo mi(perv(bv), font, text.workWidth());
1081 ii->inset->metrics(mi, dim);
1087 MetricsInfo mi(perv(bv), font, text.workWidth());
1088 const_cast<LyXText&>(text).metrics(mi, dim);
1092 RowPainter painter(bv, text, rit, y_offset, x_offset, y);
1097 void paintRows2(BufferView const & bv, LyXText const & text,
1098 RowList::iterator rit, RowList::iterator end,
1099 int xo, int & y, int yf, int y2, int yo)
1101 while (rit != end && yf < y2) {
1102 paintRows(bv, text, rit, y + yo, xo, y + text.top_y());
1104 yf += rit->height();