+int TextMetrics::singleWidth(pit_type pit, pos_type pos) const
+{
+ Buffer const & buffer = bv_->buffer();
+ ParagraphMetrics const & pm = par_metrics_[pit];
+
+ return pm.singleWidth(pos, text_->getFont(buffer, text_->getPar(pit), pos));
+}
+
+
+// only used for inset right now. should also be used for main text
+void TextMetrics::draw(PainterInfo & pi, int x, int y) const
+{
+ if (par_metrics_.empty())
+ return;
+ ParMetricsCache::const_iterator it = par_metrics_.begin();
+ ParMetricsCache::const_iterator const end = par_metrics_.end();
+ y -= it->second.ascent();
+ for (; it != end; ++it) {
+ ParagraphMetrics const & pmi = it->second;
+ y += pmi.ascent();
+ drawParagraph(pi, it->first, x, y, true);
+ y += pmi.descent();
+ }
+}
+
+
+void TextMetrics::drawParagraph(PainterInfo & pi, pit_type pit, int x, int y,
+ bool repaintAll) const
+{
+// lyxerr << " paintPar: pit: " << pit << " at y: " << y << endl;
+ int const ww = bv_->workHeight();
+
+ bv_->coordCache().parPos()[text_][pit] = Point(x, y);
+
+ ParagraphMetrics const & pm = par_metrics_[pit];
+ if (pm.rows().empty())
+ return;
+
+ RowList::const_iterator const rb = pm.rows().begin();
+ RowList::const_iterator const re = pm.rows().end();
+
+ Bidi bidi;
+
+ y -= rb->ascent();
+ for (RowList::const_iterator rit = rb; rit != re; ++rit) {
+ y += rit->ascent();
+ // Row signature; has row changed since last paint?
+ bool row_has_changed = rit->changed();
+
+ // Paint the row if a full repaint has been requested or it has
+ // changed.
+ if (repaintAll || row_has_changed) {
+ bool const inside = (y + rit->descent() >= 0
+ && y - rit->ascent() < ww);
+ // it is not needed to draw on screen if we are not inside.
+ pi.pain.setDrawingEnabled(inside);
+ RowPainter rp(pi, *text_, pit, *rit, bidi, x, y);
+ // Clear background of this row
+ // (if paragraph background was not cleared)
+ if (!repaintAll && row_has_changed)
+ pi.pain.fillRectangle(x, y - rit->ascent(),
+ width(), rit->height(),
+ text_->backgroundColor());
+
+ // Instrumentation for testing row cache (see also
+ // 12 lines lower):
+ if (lyxerr.debugging(Debug::PAINTING)) {
+ if (text_->isMainText(bv_->buffer()))
+ LYXERR(Debug::PAINTING) << "#";
+ else
+ LYXERR(Debug::PAINTING) << "[" <<
+ repaintAll << row_has_changed << "]";
+ }
+ rp.paintAppendix();
+ rp.paintDepthBar();
+ rp.paintChangeBar();
+ if (rit == rb)
+ rp.paintFirst();
+ rp.paintText();
+ if (rit + 1 == re)
+ rp.paintLast();
+ }
+ y += rit->descent();
+ }
+ // Re-enable screen drawing for future use of the painter.
+ pi.pain.setDrawingEnabled(true);
+
+ LYXERR(Debug::PAINTING) << "." << endl;
+}
+
+//int Text::pos2x(pit_type pit, pos_type pos) const