]> git.lyx.org Git - lyx.git/blobdiff - src/rowpainter.C
Point fix, earlier forgotten
[lyx.git] / src / rowpainter.C
index cc91b06678edd234e3944f7519d285615bdf8168..a59e8385bbda8be267fc7b6cb4aaada930b43ce6 100644 (file)
@@ -6,7 +6,7 @@
  * \author various
  * \author John Levon
  *
- * Full author contact details are available in file CREDITS
+ * Full author contact details are available in file CREDITS.
  */
 
 #include <config.h>
@@ -152,7 +152,8 @@ int RowPainter::singleWidth(lyx::pos_type pos) const
 
 int RowPainter::singleWidth(lyx::pos_type pos, char c) const
 {
-       return text_.singleWidth(pit_, pos, c);
+       LyXFont const & font = text_.getFont(pit_, pos);
+       return text_.singleWidth(pit_, pos, c, font);
 }
 
 
@@ -690,22 +691,22 @@ void RowPainter::paintFirst()
        y_top += paintLengthMarker(_("Space above"), parparams.spaceTop(),
                        yo_ + y_top);
 
-       Buffer const * buffer = bv_.buffer();
+       Buffer const & buffer = *bv_.buffer();
 
        LyXLayout_ptr const & layout = pit_->layout();
 
-       if (buffer->params.paragraph_separation == BufferParams::PARSEP_SKIP) {
+       if (buffer.params.paragraph_separation == BufferParams::PARSEP_SKIP) {
                if (pit_ != text_.ownerParagraphs().begin()) {
                        if (layout->latextype == LATEX_PARAGRAPH
                                && !pit_->getDepth()) {
-                               y_top += buffer->params.getDefSkip().inPixels(bv_);
+                               y_top += buffer.params.getDefSkip().inPixels(bv_);
                        } else {
                                LyXLayout_ptr const & playout =
                                        boost::prior(pit_)->layout();
                                if (playout->latextype == LATEX_PARAGRAPH
                                        && !boost::prior(pit_)->getDepth()) {
                                        // is it right to use defskip here, too? (AS)
-                                       y_top += buffer->params.getDefSkip().inPixels(bv_);
+                                       y_top += buffer.params.getDefSkip().inPixels(bv_);
                                }
                        }
                }
@@ -745,12 +746,12 @@ void RowPainter::paintFirst()
                        // printed in an extra row and has a pagebreak at
                        // the top.
                        if (layout->labeltype == LABEL_COUNTER_CHAPTER) {
-                               if (buffer->params.secnumdepth >= 0) {
+                               if (buffer.params.secnumdepth >= 0) {
                                        float spacing_val = 1.0;
                                        if (!parparams.spacing().isDefault()) {
                                                spacing_val = parparams.spacing().getValue();
                                        } else {
-                                               spacing_val = buffer->params.spacing.getValue();
+                                               spacing_val = buffer.params.spacing.getValue();
                                        }
 
                                        int const maxdesc =
@@ -793,7 +794,7 @@ void RowPainter::paintFirst()
                        if (!parparams.spacing().isDefault()) {
                                spacing_val = parparams.spacing().getValue();
                        } else {
-                               spacing_val = buffer->params.spacing.getValue();
+                               spacing_val = buffer.params.spacing.getValue();
                        }
 
                        int maxdesc =
@@ -1001,11 +1002,11 @@ void RowPainter::paintText()
 
 void RowPainter::paint()
 {
-       width_ = text_.workWidth();
-
-       // FIXME: must be a cleaner way here. Aren't these calculations
-       // belonging to row metrics ?
-       text_.prepareToPrint(pit_, row_, x_, separator_, hfill_, label_hfill_);
+       width_       = text_.workWidth();
+       x_           = row_->x();
+       separator_   = row_->fill_separator();
+       hfill_       = row_->fill_hfill();
+       label_hfill_ = row_->fill_label_hfill();
 
        // FIXME: what is this fixing ?
        if (text_.isInInset() && x_ < 0)
@@ -1041,74 +1042,15 @@ void RowPainter::paint()
 }
 
 
-} // namespace anon
-
-
-int getLengthMarkerHeight(BufferView const & bv, VSpace const & vsp)
-{
-       if (vsp.kind() == VSpace::NONE)
-               return 0;
-
-       int const arrow_size = 4;
-       int const space_size = vsp.inPixels(bv);
-
-       LyXFont font;
-       font.decSize();
-       int const min_size = max(3 * arrow_size,
-               font_metrics::maxAscent(font)
-               + font_metrics::maxDescent(font));
-
-       if (vsp.length().len().value() < 0.0)
-               return min_size;
-       else
-               return max(min_size, space_size);
-}
-
-
-void paintRow(BufferView const & bv, LyXText const & text,
-       ParagraphList::iterator pit,
-       RowList::iterator rit, int y_offset, int x_offset, int y)
-{
-       RowPainter painter(bv, text, pit, rit, y_offset, x_offset, y);
-       painter.paint();
-}
-
-
 int paintRows(BufferView const & bv, LyXText const & text,
-       RowList::iterator rit, int xo, int y, int yf, int y2, int yo)
+       ParagraphList::iterator pit, RowList::iterator rit,
+       int xo, int y, int yf, int yo)
 {
-       // fix up missing metrics() call for main LyXText
-       // calling metrics() directly is (a) slow and (b) crashs
-       if (&text == bv.text) {
-#if 1
-               // make sure all insets are updated
-               ParagraphList::iterator pit = text.ownerParagraphs().begin();
-               ParagraphList::iterator end = text.ownerParagraphs().end();
-
-               // compute inset metrics
-               for (; pit != end; ++pit) {
-                       InsetList & insetList = pit->insetlist;
-                       InsetList::iterator ii = insetList.begin();
-                       InsetList::iterator iend = insetList.end();
-                       for (; ii != iend; ++ii) {
-                               Dimension dim;
-                               LyXFont font;
-                               MetricsInfo mi(perv(bv), font, text.workWidth());
-                               ii->inset->metrics(mi, dim);
-                       }
-               }
-#else
-               LyXFont font;
-               Dimension dim;
-               MetricsInfo mi(perv(bv), font, text.workWidth());
-               const_cast<LyXText&>(text).metrics(mi, dim);
-#endif
-       }
-       const_cast<LyXText&>(text).updateRowPositions();
+       //lyxerr << "  paintRows: rit: " << &*rit << endl;
+       //const_cast<LyXText&>(text).updateRowPositions();
+       int const yy = yf - y;
+       int const y2 = bv.painter().paperHeight();
 
-       int yy = yf - y;
-       
-       ParagraphList::iterator pit = text.ownerParagraphs().begin();
        ParagraphList::iterator end = text.ownerParagraphs().end();
        bool active = false;
 
@@ -1120,7 +1062,8 @@ int paintRows(BufferView const & bv, LyXText const & text,
                        if (row == rit)
                                active = true;
                        if (active) {
-                               paintRow(bv, text, pit, row, y + yo, xo, y + text.top_y());
+                               RowPainter painter(bv, text, pit, row, y + yo, xo, y + bv.top_y());
+                               painter.paint();
                                y += row->height();
                                if (yy + y >= y2)
                                        return y;
@@ -1133,3 +1076,54 @@ int paintRows(BufferView const & bv, LyXText const & text,
        return y;
 }
 
+} // namespace anon
+
+
+int paintText(BufferView & bv)
+{
+       int const topy = bv.top_y();
+       ParagraphList::iterator pit;
+       RowList::iterator rit = bv.text->getRowNearY(topy, pit);
+       int y = rit->y() - topy;
+       return paintRows(bv, *bv.text, pit, rit, 0, y, y, 0);
+}
+
+
+void paintTextInset(BufferView & bv, LyXText & text, int x, int baseline)
+{
+       RowList::iterator rit = text.firstRow();
+       RowList::iterator end = text.endRow();
+       ParagraphList::iterator pit = text.ownerParagraphs().begin();
+
+       int y_offset = baseline - rit->ascent_of_text();
+       int y = y_offset;
+       while (rit != end && y + rit->height() <= 0) {
+               y += rit->height();
+               text.nextRow(pit, rit);
+       }
+       if (y_offset < 0)
+               paintRows(bv, text, pit, rit, x, 0, y, y);
+       else
+               paintRows(bv, text, pit, rit, x, 0, y_offset, y_offset);
+}
+
+
+int getLengthMarkerHeight(BufferView const & bv, VSpace const & vsp)
+{
+       if (vsp.kind() == VSpace::NONE)
+               return 0;
+
+       int const arrow_size = 4;
+       int const space_size = vsp.inPixels(bv);
+
+       LyXFont font;
+       font.decSize();
+       int const min_size = max(3 * arrow_size,
+               font_metrics::maxAscent(font)
+               + font_metrics::maxDescent(font));
+
+       if (vsp.length().len().value() < 0.0)
+               return min_size;
+       else
+               return max(min_size, space_size);
+}