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"
31 #include "rowpainter.h"
33 #include "lyxrow_funcs.h"
34 #include "metricsinfo.h"
38 using namespace lyx::support;
43 extern int PAPER_MARGIN;
44 extern int CHANGEBAR_MARGIN;
45 extern int LEFT_MARGIN;
49 // "temporary". We'll never get to use more
50 // references until we start adding hacks like
51 // these until other places catch up.
52 BufferView * perv(BufferView const & bv)
54 return const_cast<BufferView *>(&bv);
58 * A class used for painting an individual row of text.
62 /// initialise painter
63 RowPainter(BufferView const & bv, LyXText const & text,
64 RowList::iterator rit, int y_offset, int x_offset, int y);
69 // paint various parts
70 void paintBackground();
71 void paintSelection();
74 void paintChangeBar();
77 void paintForeignMark(double orig_x, LyXFont const & orig_font);
78 void paintHebrewComposeChar(lyx::pos_type & vpos);
79 void paintArabicComposeChar(lyx::pos_type & vpos);
80 void paintChars(lyx::pos_type & vpos, bool hebrew, bool arabic);
81 int paintPageBreak(string const & label, int y);
82 int paintAppendixStart(int y);
83 int paintLengthMarker(string const & prefix, VSpace const & vsp, int start);
85 void paintFromPos(lyx::pos_type & vpos);
86 void paintInset(lyx::pos_type const pos);
88 /// return left margin
89 int leftMargin() const;
91 /// return the font at the given pos
92 LyXFont const getFont(lyx::pos_type pos) const;
94 /// return the label font for this row
95 LyXFont const getLabelFont() const;
97 char const transformChar(char c, lyx::pos_type pos) const;
99 /// return pixel width for the given pos
100 int singleWidth(lyx::pos_type pos) const;
101 int singleWidth(lyx::pos_type pos, char c) const;
103 /// bufferview to paint on
104 BufferView const & bv_;
109 /// LyXText for the row
110 LyXText const & text_;
113 RowList::iterator row_;
116 mutable ParagraphList::iterator pit_;
130 RowPainter::RowPainter(BufferView const & bv, LyXText const & text,
131 RowList::iterator rit,
132 int y_offset, int x_offset, int y)
133 : bv_(bv), pain_(bv_.painter()), text_(text), row_(rit),
135 xo_(x_offset), yo_(y_offset), y_(y)
140 LyXFont const RowPainter::getFont(pos_type pos) const
142 return text_.getFont(pit_, pos);
146 int RowPainter::singleWidth(lyx::pos_type pos) const
148 return text_.singleWidth(pit_, pos);
152 int RowPainter::singleWidth(lyx::pos_type pos, char c) const
154 return text_.singleWidth(pit_, pos, c);
158 LyXFont const RowPainter::getLabelFont() const
160 return text_.getLabelFont(pit_);
164 char const RowPainter::transformChar(char c, lyx::pos_type pos) const
166 return text_.transformChar(c, *pit_, pos);
170 int RowPainter::leftMargin() const
172 return text_.leftMargin(*row_);
176 void RowPainter::paintInset(pos_type const pos)
178 InsetOld * inset = const_cast<InsetOld*>(pit_->getInset(pos));
182 PainterInfo pi(perv(bv_));
183 pi.base.font = getFont(pos);
184 inset->draw(pi, int(x_), yo_ + row_->baseline());
185 x_ += inset->width();
189 void RowPainter::paintHebrewComposeChar(pos_type & vpos)
191 pos_type pos = text_.vis2log(vpos);
196 char c = pit_->getChar(pos);
200 LyXFont const & font = getFont(pos);
201 int const width = font_metrics::width(c, font);
204 for (pos_type i = pos - 1; i >= 0; --i) {
205 c = pit_->getChar(i);
206 if (!Encodings::IsComposeChar_hebrew(c)) {
207 if (IsPrintableNonspace(c)) {
211 dx = (c == 'ø' || c == 'ã')
213 : (width2 - width) / 2;
220 pain_.text(int(x_) + dx, yo_ + row_->baseline(), str, font);
224 void RowPainter::paintArabicComposeChar(pos_type & vpos)
226 pos_type pos = text_.vis2log(vpos);
230 char c = pit_->getChar(pos);
231 c = transformChar(c, pos);
235 LyXFont const & font = getFont(pos);
236 int const width = font_metrics::width(c, font);
239 for (pos_type i = pos - 1; i >= 0; --i) {
240 c = pit_->getChar(i);
241 if (!Encodings::IsComposeChar_arabic(c)) {
242 if (IsPrintableNonspace(c)) {
245 dx = (width2 - width) / 2;
251 pain_.text(int(x_) + dx, yo_ + row_->baseline(), str, font);
255 void RowPainter::paintChars(pos_type & vpos, bool hebrew, bool arabic)
257 pos_type pos = text_.vis2log(vpos);
258 pos_type const last = lastPrintablePos(text_, row_);
259 LyXFont orig_font = getFont(pos);
263 str += pit_->getChar(pos);
265 unsigned char c = str[0];
266 str[0] = transformChar(c, pos);
269 bool prev_struckout(isDeletedText(*pit_, pos));
270 bool prev_newtext(isInsertedText(*pit_, pos));
274 // collect as much similar chars as we can
275 while (vpos <= last && (pos = text_.vis2log(vpos)) >= 0) {
276 char c = pit_->getChar(pos);
278 if (!IsPrintableNonspace(c))
281 if (prev_struckout != isDeletedText(*pit_, pos))
284 if (prev_newtext != isInsertedText(*pit_, pos))
287 if (arabic && Encodings::IsComposeChar_arabic(c))
289 if (hebrew && Encodings::IsComposeChar_hebrew(c))
292 if (orig_font != getFont(pos))
296 c = transformChar(c, pos);
301 if (prev_struckout) {
302 orig_font.setColor(LColor::strikeout);
303 } else if (prev_newtext) {
304 orig_font.setColor(LColor::newtext);
307 // Draw text and set the new x position
308 //lyxerr << "paint row: yo_ " << yo_ << " baseline: " << row_->baseline()
310 pain_.text(int(x_), yo_ + row_->baseline(), str, orig_font);
311 x_ += font_metrics::width(str, orig_font);
315 void RowPainter::paintForeignMark(double orig_x, LyXFont const & orig_font)
317 if (!lyxrc.mark_foreign_language)
319 if (orig_font.language() == latex_language)
321 if (orig_font.language() == bv_.buffer()->params.language)
324 int const y = yo_ + row_->baseline() + 1;
325 pain_.line(int(orig_x), y, int(x_), y, LColor::language);
329 void RowPainter::paintFromPos(pos_type & vpos)
331 pos_type const pos = text_.vis2log(vpos);
333 LyXFont const & orig_font = getFont(pos);
335 double const orig_x = x_;
337 char const c = pit_->getChar(pos);
339 if (IsInsetChar(c)) {
342 paintForeignMark(orig_x, orig_font);
346 // usual characters, no insets
348 // special case languages
349 bool const hebrew = (orig_font.language()->lang() == "hebrew");
351 orig_font.language()->lang() == "arabic" &&
352 (lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
353 lyxrc.font_norm_type == LyXRC::ISO_10646_1);
355 // draw as many chars as we can
356 if ((!hebrew && !arabic)
357 || (hebrew && !Encodings::IsComposeChar_hebrew(c))
358 || (arabic && !Encodings::IsComposeChar_arabic(c))) {
359 paintChars(vpos, hebrew, arabic);
361 paintHebrewComposeChar(vpos);
363 paintArabicComposeChar(vpos);
366 paintForeignMark(orig_x, orig_font);
372 void RowPainter::paintBackground()
374 int const x = int(xo_);
375 int const y = yo_ < 0 ? 0 : yo_;
376 int const h = yo_ < 0 ? row_->height() + yo_ : row_->height();
377 pain_.fillRectangle(x, y, width_, h, text_.backgroundColor());
381 void RowPainter::paintSelection()
383 bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params);
385 // the current selection
386 int const startx = text_.selection.start.x();
387 int const endx = text_.selection.end.x();
388 int const starty = text_.selection.start.y();
389 int const endy = text_.selection.end.y();
390 RowList::iterator startrow = text_.getRow(text_.selection.start);
391 RowList::iterator endrow = text_.getRow(text_.selection.end);
393 if (text_.bidi_same_direction) {
397 int h = row_->height();
399 if (startrow == row_ && endrow == row_) {
401 x = int(xo_) + startx;
403 pain_.fillRectangle(x, y, w, h, LColor::selection);
407 pain_.fillRectangle(x, y, w, h, LColor::selection);
409 } else if (startrow == row_) {
410 int const x = is_rtl ? int(xo_) : int(xo_ + startx);
411 int const w = is_rtl ? startx : (width_ - startx);
412 pain_.fillRectangle(x, y, w, h, LColor::selection);
413 } else if (endrow == row_) {
414 int const x = is_rtl ? int(xo_ + endx) : int(xo_);
415 int const w = is_rtl ? (width_ - endx) : endx;
416 pain_.fillRectangle(x, y, w, h, LColor::selection);
417 } else if (y_ > starty && y_ < endy) {
418 pain_.fillRectangle(int(xo_), y, width_, h, LColor::selection);
421 } else if (startrow != row_ && endrow != row_) {
422 if (y_ > starty && y_ < endy) {
424 int h = row_->height();
425 pain_.fillRectangle(int(xo_), yo_, w, h, LColor::selection);
430 if ((startrow != row_ && !is_rtl) || (endrow != row_ && is_rtl))
431 pain_.fillRectangle(int(xo_), yo_,
432 int(x_), row_->height(), LColor::selection);
434 pos_type const body_pos = pit_->beginningOfBody();
435 pos_type const last = lastPrintablePos(text_, row_);
438 for (pos_type vpos = row_->pos(); vpos <= last; ++vpos) {
439 pos_type pos = text_.vis2log(vpos);
440 double const old_tmpx = tmpx;
441 if (body_pos > 0 && pos == body_pos - 1) {
442 LyXLayout_ptr const & layout = pit_->layout();
443 LyXFont const lfont = getLabelFont();
445 tmpx += label_hfill_ + font_metrics::width(layout->labelsep, lfont);
447 if (pit_->isLineSeparator(body_pos - 1))
448 tmpx -= singleWidth(body_pos - 1);
451 if (hfillExpansion(text_, row_, pos)) {
452 tmpx += singleWidth(pos);
456 tmpx += label_hfill_;
459 else if (pit_->isSeparator(pos)) {
460 tmpx += singleWidth(pos);
464 tmpx += singleWidth(pos);
467 if ((startrow != row_ || text_.selection.start.pos() <= pos) &&
468 (endrow != row_ || pos < text_.selection.end.pos())) {
469 // Here we do not use x_ as xo_ was added to x_.
470 pain_.fillRectangle(int(old_tmpx), yo_,
471 int(tmpx - old_tmpx + 1),
472 row_->height(), LColor::selection);
476 if ((startrow != row_ && is_rtl) || (endrow != row_ && !is_rtl)) {
477 pain_.fillRectangle(int(xo_ + tmpx),
478 yo_, int(bv_.workWidth() - tmpx),
479 row_->height(), LColor::selection);
484 void RowPainter::paintChangeBar()
486 pos_type const start = row_->pos();
487 pos_type const end = lastPrintablePos(text_, row_);
489 if (!pit_->isChanged(start, end))
492 int const height = (boost::next(row_) != text_.rows().end()
493 ? row_->height() + boost::next(row_)->top_of_text()
496 pain_.fillRectangle(4, yo_, 5, height, LColor::changebar);
500 void RowPainter::paintAppendix()
502 if (!pit_->params().appendix())
505 // FIXME: can be just width_ ?
506 int const ww = bv_.workWidth();
510 if (pit_->params().startOfAppendix())
511 y += 2 * defaultRowHeight();
513 pain_.line(1, y, 1, yo_ + row_->height(), LColor::appendix);
514 pain_.line(ww - 2, y, ww - 2, yo_ + row_->height(), LColor::appendix);
518 void RowPainter::paintDepthBar()
520 Paragraph::depth_type const depth = pit_->getDepth();
525 Paragraph::depth_type prev_depth = 0;
526 if (row_ != text_.rows().begin())
527 prev_depth = boost::prior(row_)->par()->getDepth();
528 Paragraph::depth_type next_depth = 0;
530 RowList::iterator next_row = boost::next(row_);
531 if (next_row != text_.rows().end())
532 next_depth = next_row->par()->getDepth();
534 for (Paragraph::depth_type i = 1; i <= depth; ++i) {
535 int const w = PAPER_MARGIN / 5;
536 int x = int(w * i + xo_);
537 // only consider the changebar space if we're drawing outer left
539 x += CHANGEBAR_MARGIN;
540 int const h = yo_ + row_->height() - 1 - (i - next_depth - 1) * 3;
542 pain_.line(x, yo_, x, h, LColor::depthbar);
545 pain_.fillRectangle(x, yo_, w, 2, LColor::depthbar);
547 pain_.fillRectangle(x, h, w, 2, LColor::depthbar);
552 int RowPainter::paintLengthMarker(string const & prefix, VSpace const & vsp, int start)
554 if (vsp.kind() == VSpace::NONE)
557 int const arrow_size = 4;
558 int const size = getLengthMarkerHeight(bv_, vsp);
559 int const end = start + size;
561 // the label to display (if any)
563 // y-values for top arrow
565 // y-values for bottom arrow
568 str = prefix + " (" + vsp.asLyXCommand() + ")";
570 if (vsp.kind() == VSpace::VFILL) {
574 // adding or removing space
575 bool const added = vsp.kind() != VSpace::LENGTH ||
576 vsp.length().len().value() > 0.0;
577 ty1 = added ? (start + arrow_size) : start;
578 ty2 = added ? start : (start + arrow_size);
579 by1 = added ? (end - arrow_size) : end;
580 by2 = added ? end : (end - arrow_size);
583 int const leftx = int(xo_) + leftMargin();
584 int const midx = leftx + arrow_size;
585 int const rightx = midx + arrow_size;
593 font.setColor(LColor::added_space).decSize().decSize();
594 font_metrics::rectText(str, font, w, a, d);
596 pain_.rectText(leftx + 2 * arrow_size + 5,
597 start + ((end - start) / 2) + d,
601 pain_.line(leftx, ty1, midx, ty2, LColor::added_space);
602 pain_.line(midx, ty2, rightx, ty1, LColor::added_space);
605 pain_.line(leftx, by1, midx, by2, LColor::added_space);
606 pain_.line(midx, by2, rightx, by1, LColor::added_space);
609 pain_.line(midx, ty2, midx, by2, LColor::added_space);
615 int RowPainter::paintPageBreak(string const & label, int y)
618 pb_font.setColor(LColor::pagebreak).decSize();
623 font_metrics::rectText(label, pb_font, w, a, d);
625 int const text_start = int(xo_ + (width_ - w) / 2);
626 int const text_end = text_start + w;
628 pain_.rectText(text_start, y + d, label, pb_font);
630 pain_.line(int(xo_), y, text_start, y,
631 LColor::pagebreak, Painter::line_onoffdash);
632 pain_.line(text_end, y, int(xo_ + width_), y,
633 LColor::pagebreak, Painter::line_onoffdash);
635 return 3 * defaultRowHeight();
639 int RowPainter::paintAppendixStart(int y)
642 pb_font.setColor(LColor::appendix).decSize();
644 string const label = _("Appendix");
648 font_metrics::rectText(label, pb_font, w, a, d);
650 int const text_start = int(xo_ + (width_ - w) / 2);
651 int const text_end = text_start + w;
653 pain_.rectText(text_start, y + d, label, pb_font);
655 pain_.line(int(xo_ + 1), y, text_start, y, LColor::appendix);
656 pain_.line(text_end, y, int(xo_ + width_ - 2), y, LColor::appendix);
658 return 3 * defaultRowHeight();
662 void RowPainter::paintFirst()
664 ParagraphParameters const & parparams = pit_->params();
668 // start of appendix?
669 if (parparams.startOfAppendix())
670 y_top += paintAppendixStart(yo_ + y_top + 2 * defaultRowHeight());
673 if (row_ == text_.rows().begin() && !text_.isInInset())
674 y_top += PAPER_MARGIN;
676 // draw a top pagebreak
677 if (parparams.pagebreakTop())
678 y_top += paintPageBreak(_("Page Break (top)"),
679 yo_ + y_top + 2 * defaultRowHeight());
681 // draw the additional space if needed:
682 y_top += paintLengthMarker(_("Space above"), parparams.spaceTop(),
685 Buffer const * buffer = bv_.buffer();
687 LyXLayout_ptr const & layout = pit_->layout();
689 if (buffer->params.paragraph_separation == BufferParams::PARSEP_SKIP) {
690 if (pit_ != text_.ownerParagraphs().begin()) {
691 if (layout->latextype == LATEX_PARAGRAPH
692 && !pit_->getDepth()) {
693 y_top += buffer->params.getDefSkip().inPixels(bv_);
695 LyXLayout_ptr const & playout =
696 boost::prior(pit_)->layout();
697 if (playout->latextype == LATEX_PARAGRAPH
698 && !boost::prior(pit_)->getDepth()) {
699 // is it right to use defskip here, too? (AS)
700 y_top += buffer->params.getDefSkip().inPixels(bv_);
706 int const ww = bv_.workWidth();
709 if (parparams.lineTop()) {
710 int const asc = font_metrics::ascent('x', getFont(0));
714 int const w = (text_.isInInset() ? text_.inset_owner->width() : ww);
715 int const xp = static_cast<int>(text_.isInInset() ? xo_ : 0);
716 pain_.line(xp, yo_ + y_top, xp + w, yo_ + y_top,
717 LColor::topline, Painter::line_solid,
718 Painter::line_thick);
723 bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params);
725 // should we print a label?
726 if (layout->labeltype >= LABEL_STATIC
727 && (layout->labeltype != LABEL_STATIC
728 || layout->latextype != LATEX_ENVIRONMENT
729 || isFirstInSequence(pit_, text_.ownerParagraphs()))) {
731 LyXFont font = getLabelFont();
732 if (!pit_->getLabelstring().empty()) {
734 string const str = pit_->getLabelstring();
736 // this is special code for the chapter layout. This is
737 // printed in an extra row and has a pagebreak at
739 if (layout->labeltype == LABEL_COUNTER_CHAPTER) {
740 if (buffer->params.secnumdepth >= 0) {
741 float spacing_val = 1.0;
742 if (!parparams.spacing().isDefault()) {
743 spacing_val = parparams.spacing().getValue();
745 spacing_val = buffer->params.spacing.getValue();
749 int(font_metrics::maxDescent(font) * layout->spacing.getValue() * spacing_val)
750 + int(layout->parsep) * defaultRowHeight();
753 x = ww - leftMargin() -
754 font_metrics::width(str, font);
758 yo_ + row_->baseline() -
759 row_->ascent_of_text() - maxdesc,
764 x = ww - leftMargin()
765 + font_metrics::width(layout->labelsep, font);
767 x = x_ - font_metrics::width(layout->labelsep, font)
768 - font_metrics::width(str, font);
771 pain_.text(int(x), yo_ + row_->baseline(), str, font);
775 // the labels at the top of an environment.
776 // More or less for bibliography
777 } else if (isFirstInSequence(pit_, text_.ownerParagraphs()) &&
778 (layout->labeltype == LABEL_TOP_ENVIRONMENT ||
779 layout->labeltype == LABEL_BIBLIO ||
780 layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)) {
781 LyXFont font = getLabelFont();
782 if (!pit_->getLabelstring().empty()) {
783 string const str = pit_->getLabelstring();
784 float spacing_val = 1.0;
785 if (!parparams.spacing().isDefault()) {
786 spacing_val = parparams.spacing().getValue();
788 spacing_val = buffer->params.spacing.getValue();
792 int(font_metrics::maxDescent(font) * layout->spacing.getValue() * spacing_val
793 + (layout->labelbottomsep * defaultRowHeight()));
796 if (layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
797 x = ((is_rtl ? leftMargin() : x_)
798 + ww - text_.rightMargin(*bv_.buffer(), *row_)) / 2;
799 x -= font_metrics::width(str, font) / 2;
801 x = ww - leftMargin() -
802 font_metrics::width(str, font);
805 yo_ + row_->baseline() - row_->ascent_of_text() - maxdesc,
812 void RowPainter::paintLast()
814 ParagraphParameters const & parparams = pit_->params();
815 int y_bottom = row_->height() - 1;
818 if (boost::next(row_) == text_.rows().end() && !text_.isInInset())
819 y_bottom -= PAPER_MARGIN;
821 int const ww = bv_.workWidth();
823 // draw a bottom pagebreak
824 if (parparams.pagebreakBottom()) {
825 y_bottom -= paintPageBreak(_("Page Break (bottom)"),
826 yo_ + y_bottom - 2 * defaultRowHeight());
829 // draw the additional space if needed:
830 int const height = getLengthMarkerHeight(bv_, parparams.spaceBottom());
831 y_bottom -= paintLengthMarker(_("Space below"), parparams.spaceBottom(),
832 yo_ + y_bottom - height);
834 // draw a bottom line
835 if (parparams.lineBottom()) {
836 int const asc = font_metrics::ascent('x',
837 getFont(max(pos_type(0), pit_->size() - 1)));
841 int const w = text_.isInInset() ? text_.inset_owner->width() : ww;
842 int const xp = int(text_.isInInset() ? xo_ : 0);
843 int const y = yo_ + y_bottom;
844 pain_.line(xp, y, xp + w, y, LColor::topline, Painter::line_solid,
845 Painter::line_thick);
850 bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params);
851 int const endlabel = getEndLabel(pit_, text_.ownerParagraphs());
856 case END_LABEL_FILLED_BOX:
858 LyXFont const font = getLabelFont();
859 int const size = int(0.75 * font_metrics::maxAscent(font));
860 int const y = (yo_ + row_->baseline()) - size;
861 int x = is_rtl ? LEFT_MARGIN : ww - PAPER_MARGIN - size;
863 if (row_->fill() <= size)
864 x += (size - row_->fill() + 1) * (is_rtl ? -1 : 1);
866 if (endlabel == END_LABEL_BOX)
867 pain_.rectangle(x, y, size, size, LColor::eolmarker);
869 pain_.fillRectangle(x, y, size, size, LColor::eolmarker);
872 case END_LABEL_STATIC:
874 LyXFont font = getLabelFont();
875 string const & str = pit_->layout()->endlabelstring();
876 double const x = is_rtl ?
877 x_ - font_metrics::width(str, font)
878 : ww - text_.rightMargin(*bv_.buffer(), *row_) - row_->fill();
879 pain_.text(int(x), yo_ + row_->baseline(), str, font);
882 case END_LABEL_NO_LABEL:
888 void RowPainter::paintText()
890 pos_type const last = lastPrintablePos(text_, row_);
891 pos_type body_pos = pit_->beginningOfBody();
893 (body_pos - 1 > last || !pit_->isLineSeparator(body_pos - 1))) {
897 LyXLayout_ptr const & layout = pit_->layout();
899 bool running_strikeout = false;
900 bool is_struckout = false;
901 int last_strikeout_x = 0;
903 pos_type vpos = row_->pos();
904 while (vpos <= last) {
905 if (x_ > bv_.workWidth())
907 pos_type pos = text_.vis2log(vpos);
909 if (pos >= pit_->size()) {
914 if (x_ + singleWidth(pos) < 0) {
915 x_ += singleWidth(pos);
920 is_struckout = isDeletedText(*pit_, pos);
922 if (is_struckout && !running_strikeout) {
923 running_strikeout = true;
924 last_strikeout_x = int(x_);
927 bool const highly_editable_inset = pit_->isInset(pos)
928 && isHighlyEditableInset(pit_->getInset(pos));
930 // if we reach the end of a struck out range, paint it
931 // we also don't paint across things like tables
932 if (running_strikeout && (highly_editable_inset || !is_struckout)) {
933 int const middle = yo_ + row_->top_of_text()
934 + (row_->baseline() - row_->top_of_text()) / 2;
935 pain_.line(last_strikeout_x, middle, int(x_), middle,
936 LColor::strikeout, Painter::line_solid, Painter::line_thin);
937 running_strikeout = false;
940 if (body_pos > 0 && pos == body_pos - 1) {
941 int const lwidth = font_metrics::width(layout->labelsep,
944 x_ += label_hfill_ + lwidth - singleWidth(body_pos - 1);
947 if (pit_->isHfill(pos)) {
950 int const y0 = yo_ + row_->baseline();
951 int const y1 = y0 - defaultRowHeight() / 2;
953 pain_.line(int(x_), y1, int(x_), y0, LColor::added_space);
955 if (hfillExpansion(text_, row_, pos)) {
956 int const y2 = (y0 + y1) / 2;
958 if (pos >= body_pos) {
959 pain_.line(int(x_), y2, int(x_ + hfill_), y2,
961 Painter::line_onoffdash);
964 pain_.line(int(x_), y2, int(x_ + label_hfill_), y2,
966 Painter::line_onoffdash);
969 pain_.line(int(x_), y1, int(x_), y0, LColor::added_space);
973 } else if (pit_->isSeparator(pos)) {
974 x_ += singleWidth(pos);
983 // if we reach the end of a struck out range, paint it
984 if (running_strikeout) {
985 int const middle = yo_ + row_->top_of_text()
986 + ((row_->baseline() - row_->top_of_text()) / 2);
987 pain_.line(last_strikeout_x, middle, int(x_), middle,
988 LColor::strikeout, Painter::line_solid, Painter::line_thin);
989 running_strikeout = false;
994 void RowPainter::paint()
996 width_ = text_.workWidth();
998 // FIXME: must be a cleaner way here. Aren't these calculations
999 // belonging to row metrics ?
1000 text_.prepareToPrint(row_, x_, separator_, hfill_, label_hfill_);
1002 // FIXME: what is this fixing ?
1003 if (text_.isInInset() && x_ < 0)
1007 // If we're *not* at the top-level of rows, then the
1008 // background has already been cleared.
1009 if (&text_ == bv_.text)
1012 // paint the selection background
1013 if (text_.selection.set())
1016 // vertical lines for appendix
1019 // environment depth brackets
1025 if (row_->isParStart())
1028 if (isParEnd(text_, row_))
1039 int getLengthMarkerHeight(BufferView const & bv, VSpace const & vsp)
1041 if (vsp.kind() == VSpace::NONE)
1044 int const arrow_size = 4;
1045 int const space_size = vsp.inPixels(bv);
1049 int const min_size = max(3 * arrow_size,
1050 font_metrics::maxAscent(font)
1051 + font_metrics::maxDescent(font));
1053 if (vsp.length().len().value() < 0.0)
1056 return max(min_size, space_size);
1060 void paintRowsHelper(BufferView const & bv, LyXText const & text,
1061 RowList::iterator rit, int y_offset, int x_offset, int y)
1063 // fix up missing metrics() call for main LyXText
1064 // calling metrics() directly is (a) slow and (b) crashs
1065 if (&text == bv.text) {
1067 // make sure all insets are updated
1068 ParagraphList::iterator pit = text.ownerParagraphs().begin();
1069 ParagraphList::iterator end = text.ownerParagraphs().end();
1071 // compute inset metrics
1072 for (; pit != end; ++pit) {
1073 InsetList & insetList = pit->insetlist;
1074 InsetList::iterator ii = insetList.begin();
1075 InsetList::iterator iend = insetList.end();
1076 for (; ii != iend; ++ii) {
1079 MetricsInfo mi(perv(bv), font, text.workWidth());
1080 ii->inset->metrics(mi, dim);
1086 MetricsInfo mi(perv(bv), font, text.workWidth());
1087 const_cast<LyXText&>(text).metrics(mi, dim);
1091 RowPainter painter(bv, text, rit, y_offset, x_offset, y);
1096 int paintRows(BufferView const & bv, LyXText const & text,
1097 RowList::iterator rit, int xo, int y, int yf, int y2, int yo)
1099 RowList::iterator end = text.rows().end();
1100 while (rit != end && yf < y2) {
1101 //const_cast<LyXText &>(text).setHeightOfRow(rit);
1102 paintRowsHelper(bv, text, rit, y + yo, xo, y + text.top_y());
1104 yf += rit->height();