+
+
+ViewMetricsInfo BufferView::Pimpl::metrics()
+{
+ // Remove old position cache
+ theCoords.clear();
+ BufferView & bv = *bv_;
+ LyXText * const text = bv.text();
+ if (anchor_ref_ > int(text->paragraphs().size() - 1)) {
+ anchor_ref_ = int(text->paragraphs().size() - 1);
+ offset_ref_ = 0;
+ }
+
+ lyx::pit_type const pit = anchor_ref_;
+ int pit1 = pit;
+ int pit2 = pit;
+ size_t const npit = text->paragraphs().size();
+
+ lyxerr << BOOST_CURRENT_FUNCTION
+ << " npit: " << npit
+ << " pit1: " << pit1
+ << " pit2: " << pit2
+ << endl;
+
+ // Rebreak anchor par
+ text->redoParagraph(pit);
+ int y0 = text->getPar(pit1).ascent() - offset_ref_;
+
+ // Redo paragraphs above cursor if necessary
+ int y1 = y0;
+ while (y1 > 0 && pit1 > 0) {
+ y1 -= text->getPar(pit1).ascent();
+ --pit1;
+ text->redoParagraph(pit1);
+ y1 -= text->getPar(pit1).descent();
+ }
+
+
+ // Take care of ascent of first line
+ y1 -= text->getPar(pit1).ascent();
+
+ // Normalize anchor for next time
+ anchor_ref_ = pit1;
+ offset_ref_ = -y1;
+
+ // Grey at the beginning is ugly
+ if (pit1 == 0 && y1 > 0) {
+ y0 -= y1;
+ y1 = 0;
+ anchor_ref_ = 0;
+ }
+
+ // Redo paragraphs below cursor if necessary
+ int y2 = y0;
+ while (y2 < bv.workHeight() && pit2 < int(npit) - 1) {
+ y2 += text->getPar(pit2).descent();
+ ++pit2;
+ text->redoParagraph(pit2);
+ y2 += text->getPar(pit2).ascent();
+ }
+
+ // Take care of descent of last line
+ y2 += text->getPar(pit2).descent();
+
+ // The coordinates of all these paragraphs are correct, cache them
+ int y = y1;
+ for (lyx::pit_type pit = pit1; pit <= pit2; ++pit) {
+ y += text->getPar(pit).ascent();
+ theCoords.parPos()[text][pit] = Point(0, y);
+ y += text->getPar(pit).descent();
+ }
+
+ lyxerr << BOOST_CURRENT_FUNCTION
+ << " y1: " << y1
+ << " y2: " << y2
+ << endl;
+
+ return ViewMetricsInfo(pit1, pit2, y1, y2);
+}