]> git.lyx.org Git - lyx.git/blobdiff - src/TextMetrics.cpp
Amend 207eaeee9071cb
[lyx.git] / src / TextMetrics.cpp
index abeb5cfbb8548b1aaa033aeb2e71ec00693d1966..ce8cfe552d476d8a523d4a86f27b2b0a3b9244fe 100644 (file)
@@ -216,6 +216,56 @@ void TextMetrics::newParMetricsUp()
 }
 
 
+void TextMetrics::updateMetrics(pit_type const anchor_pit, int const anchor_ypos,
+                                int const bv_height)
+{
+       LASSERT(text_->isMainText(), return);
+       pit_type const npit = pit_type(text_->paragraphs().size());
+
+       if (!contains(anchor_pit))
+               // Rebreak anchor paragraph.
+               redoParagraph(anchor_pit);
+       ParagraphMetrics & anchor_pm = parMetrics(anchor_pit);
+       anchor_pm.setPosition(anchor_ypos);
+
+       // Redo paragraphs above anchor if necessary.
+       int y1 = anchor_ypos - anchor_pm.ascent();
+       // We are now just above the anchor paragraph.
+       pit_type pit1 = anchor_pit - 1;
+       for (; pit1 >= 0 && y1 > 0; --pit1) {
+               if (!contains(pit1))
+                       redoParagraph(pit1);
+               ParagraphMetrics & pm = parMetrics(pit1);
+               y1 -= pm.descent();
+               // Save the paragraph position in the cache.
+               pm.setPosition(y1);
+               y1 -= pm.ascent();
+       }
+
+       // Redo paragraphs below the anchor if necessary.
+       int y2 = anchor_ypos + anchor_pm.descent();
+       // We are now just below the anchor paragraph.
+       pit_type pit2 = anchor_pit + 1;
+       for (; pit2 < npit && y2 < bv_height; ++pit2) {
+               if (!contains(pit2))
+                       redoParagraph(pit2);
+               ParagraphMetrics & pm = parMetrics(pit2);
+               y2 += pm.ascent();
+               // Save the paragraph position in the cache.
+               pm.setPosition(y2);
+               y2 += pm.descent();
+       }
+
+       LYXERR(Debug::PAINTING, "TextMetrics::updateMetrics "
+               << " anchor pit = " << anchor_pit
+               << " anchor ypos = " << anchor_ypos
+               << " y1 = " << y1
+               << " y2 = " << y2
+               << " pit1 = " << pit1
+               << " pit2 = " << pit2);
+}
+
+
 bool TextMetrics::metrics(MetricsInfo const & mi, Dimension & dim, int min_width)
 {
        LBUFERR(mi.base.textwidth > 0);
@@ -1497,8 +1547,8 @@ pit_type TextMetrics::getPitNearY(int y)
        }
 
        for (; it != et; ++it) {
-               LYXERR(Debug::PAINTING, "examining: pit: " << it->first
-                       << " y: " << it->second.position());
+               // LYXERR(Debug::PAINTING, "examining: pit: " << it->first
+               //      << " y: " << it->second.position());
 
                if (it->first >= pit && it->second.top() <= y) {
                        pit = it->first;