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"
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 ParagraphList::iterator pit,
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 ParagraphList::iterator pit, RowList::iterator rit,
133 int y_offset, int x_offset, int y)
134 : bv_(bv), pain_(bv_.painter()), text_(text), row_(rit),
135 pit_(pit), 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 LyXFont const & font = text_.getFont(pit_, pos);
155 return text_.singleWidth(pit_, pos, c, font);
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(pit_, *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 = lastPos(*pit_, 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 (c == Paragraph::META_INSET) {
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 = lastPos(*pit_, 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(*pit_, 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 = lastPos(*pit_, row_);
490 if (!pit_->isChanged(start, end))
493 int const height = (row_ == text_.lastRow())
495 : 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_.firstRow()) {
528 ParagraphList::iterator pit2 = pit_;
529 if (row_ == pit2->rows.begin())
531 prev_depth = pit2->getDepth();
534 Paragraph::depth_type next_depth = 0;
535 if (row_ != text_.lastRow()) {
536 ParagraphList::iterator pit2 = pit_;
537 if (boost::next(row_) == pit2->rows.end())
539 next_depth = pit2->getDepth();
542 for (Paragraph::depth_type i = 1; i <= depth; ++i) {
543 int const w = PAPER_MARGIN / 5;
544 int x = int(w * i + xo_);
545 // only consider the changebar space if we're drawing outer left
547 x += CHANGEBAR_MARGIN;
548 int const h = yo_ + row_->height() - 1 - (i - next_depth - 1) * 3;
550 pain_.line(x, yo_, x, h, LColor::depthbar);
553 pain_.fillRectangle(x, yo_, w, 2, LColor::depthbar);
555 pain_.fillRectangle(x, h, w, 2, LColor::depthbar);
560 int RowPainter::paintLengthMarker(string const & prefix, VSpace const & vsp, int start)
562 if (vsp.kind() == VSpace::NONE)
565 int const arrow_size = 4;
566 int const size = getLengthMarkerHeight(bv_, vsp);
567 int const end = start + size;
569 // the label to display (if any)
571 // y-values for top arrow
573 // y-values for bottom arrow
576 str = prefix + " (" + vsp.asLyXCommand() + ")";
578 if (vsp.kind() == VSpace::VFILL) {
582 // adding or removing space
583 bool const added = vsp.kind() != VSpace::LENGTH ||
584 vsp.length().len().value() > 0.0;
585 ty1 = added ? (start + arrow_size) : start;
586 ty2 = added ? start : (start + arrow_size);
587 by1 = added ? (end - arrow_size) : end;
588 by2 = added ? end : (end - arrow_size);
591 int const leftx = int(xo_) + leftMargin();
592 int const midx = leftx + arrow_size;
593 int const rightx = midx + arrow_size;
601 font.setColor(LColor::added_space);
604 font_metrics::rectText(str, font, w, a, d);
606 pain_.rectText(leftx + 2 * arrow_size + 5,
607 start + ((end - start) / 2) + d,
609 LColor::none, LColor::none);
612 pain_.line(leftx, ty1, midx, ty2, LColor::added_space);
613 pain_.line(midx, ty2, rightx, ty1, LColor::added_space);
616 pain_.line(leftx, by1, midx, by2, LColor::added_space);
617 pain_.line(midx, by2, rightx, by1, LColor::added_space);
620 pain_.line(midx, ty2, midx, by2, LColor::added_space);
626 int RowPainter::paintPageBreak(string const & label, int y)
629 pb_font.setColor(LColor::pagebreak);
635 font_metrics::rectText(label, pb_font, w, a, d);
637 int const text_start = int(xo_ + (width_ - w) / 2);
638 int const text_end = text_start + w;
640 pain_.rectText(text_start, y + d, label, pb_font, LColor::none, LColor::none);
642 pain_.line(int(xo_), y, text_start, y,
643 LColor::pagebreak, Painter::line_onoffdash);
644 pain_.line(text_end, y, int(xo_ + width_), y,
645 LColor::pagebreak, Painter::line_onoffdash);
647 return 3 * defaultRowHeight();
651 int RowPainter::paintAppendixStart(int y)
654 pb_font.setColor(LColor::appendix);
657 string const label = _("Appendix");
661 font_metrics::rectText(label, pb_font, w, a, d);
663 int const text_start = int(xo_ + (width_ - w) / 2);
664 int const text_end = text_start + w;
666 pain_.rectText(text_start, y + d, label, pb_font, LColor::none, LColor::none);
668 pain_.line(int(xo_ + 1), y, text_start, y, LColor::appendix);
669 pain_.line(text_end, y, int(xo_ + width_ - 2), y, LColor::appendix);
671 return 3 * defaultRowHeight();
675 void RowPainter::paintFirst()
677 ParagraphParameters const & parparams = pit_->params();
681 // start of appendix?
682 if (parparams.startOfAppendix())
683 y_top += paintAppendixStart(yo_ + y_top + 2 * defaultRowHeight());
686 if (row_ == text_.firstRow() && !text_.isInInset())
687 y_top += PAPER_MARGIN;
689 // draw a top pagebreak
690 if (parparams.pagebreakTop())
691 y_top += paintPageBreak(_("Page Break (top)"),
692 yo_ + y_top + 2 * defaultRowHeight());
694 // draw the additional space if needed:
695 y_top += paintLengthMarker(_("Space above"), parparams.spaceTop(),
698 Buffer const & buffer = *bv_.buffer();
700 LyXLayout_ptr const & layout = pit_->layout();
702 if (buffer.params().paragraph_separation == BufferParams::PARSEP_SKIP) {
703 if (pit_ != text_.ownerParagraphs().begin()) {
704 if (layout->latextype == LATEX_PARAGRAPH
705 && !pit_->getDepth()) {
706 y_top += buffer.params().getDefSkip().inPixels(bv_);
708 LyXLayout_ptr const & playout =
709 boost::prior(pit_)->layout();
710 if (playout->latextype == LATEX_PARAGRAPH
711 && !boost::prior(pit_)->getDepth()) {
712 // is it right to use defskip here, too? (AS)
713 y_top += buffer.params().getDefSkip().inPixels(bv_);
719 int const ww = bv_.workWidth();
722 if (parparams.lineTop()) {
723 int const asc = font_metrics::ascent('x', getFont(0));
727 int const w = (text_.isInInset() ? text_.inset_owner->width() : ww);
728 int const xp = static_cast<int>(text_.isInInset() ? xo_ : 0);
729 pain_.line(xp, yo_ + y_top, xp + w, yo_ + y_top,
730 LColor::topline, Painter::line_solid,
731 Painter::line_thick);
736 bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params());
738 // should we print a label?
739 if (layout->labeltype >= LABEL_STATIC
740 && (layout->labeltype != LABEL_STATIC
741 || layout->latextype != LATEX_ENVIRONMENT
742 || isFirstInSequence(pit_, text_.ownerParagraphs()))) {
744 LyXFont font = getLabelFont();
745 if (!pit_->getLabelstring().empty()) {
747 string const str = pit_->getLabelstring();
749 // this is special code for the chapter layout. This is
750 // printed in an extra row and has a pagebreak at
752 if (layout->counter == "chapter") {
753 if (buffer.params().secnumdepth >= 0) {
754 float spacing_val = 1.0;
755 if (!parparams.spacing().isDefault()) {
756 spacing_val = parparams.spacing().getValue();
758 spacing_val = buffer.params().spacing().getValue();
762 int(font_metrics::maxDescent(font) * layout->spacing.getValue() * spacing_val)
763 + int(layout->parsep) * defaultRowHeight();
766 x = ww - leftMargin() -
767 font_metrics::width(str, font);
771 yo_ + row_->baseline() -
772 row_->ascent_of_text() - maxdesc,
777 x = ww - leftMargin()
778 + font_metrics::width(layout->labelsep, font);
780 x = x_ - font_metrics::width(layout->labelsep, font)
781 - font_metrics::width(str, font);
784 pain_.text(int(x), yo_ + row_->baseline(), str, font);
788 // the labels at the top of an environment.
789 // More or less for bibliography
790 } else if (isFirstInSequence(pit_, text_.ownerParagraphs()) &&
791 (layout->labeltype == LABEL_TOP_ENVIRONMENT ||
792 layout->labeltype == LABEL_BIBLIO ||
793 layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)) {
794 LyXFont font = getLabelFont();
795 if (!pit_->getLabelstring().empty()) {
796 string const str = pit_->getLabelstring();
797 float spacing_val = 1.0;
798 if (!parparams.spacing().isDefault()) {
799 spacing_val = parparams.spacing().getValue();
801 spacing_val = buffer.params().spacing().getValue();
805 int(font_metrics::maxDescent(font) * layout->spacing.getValue() * spacing_val
806 + (layout->labelbottomsep * defaultRowHeight()));
809 if (layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
810 x = ((is_rtl ? leftMargin() : x_)
811 + ww - text_.rightMargin(pit_, *bv_.buffer(), *row_)) / 2;
812 x -= font_metrics::width(str, font) / 2;
814 x = ww - leftMargin() -
815 font_metrics::width(str, font);
818 yo_ + row_->baseline() - row_->ascent_of_text() - maxdesc,
825 void RowPainter::paintLast()
827 ParagraphParameters const & parparams = pit_->params();
828 int y_bottom = row_->height() - 1;
831 if (row_ == text_.lastRow() && !text_.isInInset())
832 y_bottom -= PAPER_MARGIN;
834 int const ww = bv_.workWidth();
836 // draw a bottom pagebreak
837 if (parparams.pagebreakBottom()) {
838 y_bottom -= paintPageBreak(_("Page Break (bottom)"),
839 yo_ + y_bottom - 2 * defaultRowHeight());
842 // draw the additional space if needed:
843 int const height = getLengthMarkerHeight(bv_, parparams.spaceBottom());
844 y_bottom -= paintLengthMarker(_("Space below"), parparams.spaceBottom(),
845 yo_ + y_bottom - height);
847 // draw a bottom line
848 if (parparams.lineBottom()) {
849 int const asc = font_metrics::ascent('x',
850 getFont(max(pos_type(0), pit_->size() - 1)));
854 int const w = text_.isInInset() ? text_.inset_owner->width() : ww;
855 int const xp = int(text_.isInInset() ? xo_ : 0);
856 int const y = yo_ + y_bottom;
857 pain_.line(xp, y, xp + w, y, LColor::topline, Painter::line_solid,
858 Painter::line_thick);
863 bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params());
864 int const endlabel = getEndLabel(pit_, text_.ownerParagraphs());
869 case END_LABEL_FILLED_BOX:
871 LyXFont const font = getLabelFont();
872 int const size = int(0.75 * font_metrics::maxAscent(font));
873 int const y = (yo_ + row_->baseline()) - size;
874 int x = is_rtl ? LEFT_MARGIN : ww - PAPER_MARGIN - size;
876 if (row_->fill() <= size)
877 x += (size - row_->fill() + 1) * (is_rtl ? -1 : 1);
879 if (endlabel == END_LABEL_BOX)
880 pain_.rectangle(x, y, size, size, LColor::eolmarker);
882 pain_.fillRectangle(x, y, size, size, LColor::eolmarker);
885 case END_LABEL_STATIC:
887 LyXFont font = getLabelFont();
888 string const & str = pit_->layout()->endlabelstring();
889 double const x = is_rtl ?
890 x_ - font_metrics::width(str, font)
891 : ww - text_.rightMargin(pit_, *bv_.buffer(), *row_) - row_->fill();
892 pain_.text(int(x), yo_ + row_->baseline(), str, font);
895 case END_LABEL_NO_LABEL:
901 void RowPainter::paintText()
903 pos_type const last = lastPos(*pit_, row_);
904 pos_type body_pos = pit_->beginningOfBody();
906 (body_pos - 1 > last || !pit_->isLineSeparator(body_pos - 1))) {
910 LyXLayout_ptr const & layout = pit_->layout();
912 bool running_strikeout = false;
913 bool is_struckout = false;
914 int last_strikeout_x = 0;
916 pos_type vpos = row_->pos();
917 while (vpos <= last) {
918 if (x_ > bv_.workWidth())
920 pos_type pos = text_.vis2log(vpos);
922 if (pos >= pit_->size()) {
927 if (x_ + singleWidth(pos) < 0) {
928 x_ += singleWidth(pos);
933 is_struckout = isDeletedText(*pit_, pos);
935 if (is_struckout && !running_strikeout) {
936 running_strikeout = true;
937 last_strikeout_x = int(x_);
940 bool const highly_editable_inset = pit_->isInset(pos)
941 && isHighlyEditableInset(pit_->getInset(pos));
943 // if we reach the end of a struck out range, paint it
944 // we also don't paint across things like tables
945 if (running_strikeout && (highly_editable_inset || !is_struckout)) {
946 int const middle = yo_ + row_->top_of_text()
947 + (row_->baseline() - row_->top_of_text()) / 2;
948 pain_.line(last_strikeout_x, middle, int(x_), middle,
949 LColor::strikeout, Painter::line_solid, Painter::line_thin);
950 running_strikeout = false;
953 if (body_pos > 0 && pos == body_pos - 1) {
954 int const lwidth = font_metrics::width(layout->labelsep,
957 x_ += label_hfill_ + lwidth - singleWidth(body_pos - 1);
960 if (pit_->isHfill(pos)) {
963 int const y0 = yo_ + row_->baseline();
964 int const y1 = y0 - defaultRowHeight() / 2;
966 pain_.line(int(x_), y1, int(x_), y0, LColor::added_space);
968 if (hfillExpansion(*pit_, row_, pos)) {
969 int const y2 = (y0 + y1) / 2;
971 if (pos >= body_pos) {
972 pain_.line(int(x_), y2, int(x_ + hfill_), y2,
974 Painter::line_onoffdash);
977 pain_.line(int(x_), y2, int(x_ + label_hfill_), y2,
979 Painter::line_onoffdash);
982 pain_.line(int(x_), y1, int(x_), y0, LColor::added_space);
986 } else if (pit_->isSeparator(pos)) {
987 x_ += singleWidth(pos);
996 // if we reach the end of a struck out range, paint it
997 if (running_strikeout) {
998 int const middle = yo_ + row_->top_of_text()
999 + ((row_->baseline() - row_->top_of_text()) / 2);
1000 pain_.line(last_strikeout_x, middle, int(x_), middle,
1001 LColor::strikeout, Painter::line_solid, Painter::line_thin);
1002 running_strikeout = false;
1007 void RowPainter::paint()
1009 width_ = text_.workWidth();
1011 separator_ = row_->fill_separator();
1012 hfill_ = row_->fill_hfill();
1013 label_hfill_ = row_->fill_label_hfill();
1015 // FIXME: what is this fixing ?
1016 if (text_.isInInset() && x_ < 0)
1020 // If we're *not* at the top-level of rows, then the
1021 // background has already been cleared.
1022 if (&text_ == bv_.text)
1025 // paint the selection background
1026 if (text_.selection.set())
1029 // vertical lines for appendix
1032 // environment depth brackets
1038 if (row_->isParStart())
1041 if (isParEnd(*pit_, row_))
1049 int paintRows(BufferView const & bv, LyXText const & text,
1050 ParagraphList::iterator pit, RowList::iterator rit,
1051 int xo, int y, int yf, int yo)
1053 //lyxerr << " paintRows: rit: " << &*rit << endl;
1054 //const_cast<LyXText&>(text).updateRowPositions();
1055 int const yy = yf - y;
1056 int const y2 = bv.painter().paperHeight();
1058 ParagraphList::iterator end = text.ownerParagraphs().end();
1059 bool active = false;
1061 for ( ; pit != end; ++pit) {
1062 RowList::iterator row = pit->rows.begin();
1063 RowList::iterator rend = pit->rows.end();
1065 for ( ; row != rend; ++row) {
1069 RowPainter painter(bv, text, pit, row, y + yo, xo, y + bv.top_y());
1075 //lyxerr << " paintRows: row: " << &*row << " ignored" << endl;
1086 int paintText(BufferView & bv)
1088 int const topy = bv.top_y();
1089 ParagraphList::iterator pit;
1090 RowList::iterator rit = bv.text->getRowNearY(topy, pit);
1091 int y = rit->y() - topy;
1092 return paintRows(bv, *bv.text, pit, rit, 0, y, y, 0);
1096 void paintTextInset(BufferView & bv, LyXText & text, int x, int baseline)
1098 RowList::iterator rit = text.firstRow();
1099 RowList::iterator end = text.endRow();
1100 ParagraphList::iterator pit = text.ownerParagraphs().begin();
1102 int y_offset = baseline - rit->ascent_of_text();
1104 while (rit != end && y + rit->height() <= 0) {
1106 text.nextRow(pit, rit);
1109 paintRows(bv, text, pit, rit, x, 0, y, y);
1111 paintRows(bv, text, pit, rit, x, 0, y_offset, y_offset);
1115 int getLengthMarkerHeight(BufferView const & bv, VSpace const & vsp)
1117 if (vsp.kind() == VSpace::NONE)
1120 int const arrow_size = 4;
1121 int const space_size = vsp.inPixels(bv);
1125 int const min_size = max(3 * arrow_size,
1126 font_metrics::maxAscent(font)
1127 + font_metrics::maxDescent(font));
1129 if (vsp.length().len().value() < 0.0)
1132 return max(min_size, space_size);