]> git.lyx.org Git - features.git/commitdiff
Add code for debugging inset metrics (switched off by default)
authorGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Fri, 3 Nov 2006 15:39:58 +0000 (15:39 +0000)
committerGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Fri, 3 Nov 2006 15:39:58 +0000 (15:39 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15714 a592a061-630c-0410-9148-cb99ea01b6c8

src/rowpainter.C

index a35b3a4acbab375cb07e87f719737114fc3034ad..a2936fe8d96be1500a54897165c960be6663a723 100644 (file)
@@ -156,6 +156,11 @@ int RowPainter::leftMargin() const
 }
 
 
+// If you want to debug inset metrics uncomment the following line:
+// #define DEBUG_METRICS
+// This draws green lines around each inset.
+
+
 void RowPainter::paintInset(pos_type const pos, LyXFont const & font)
 {
        InsetBase const * inset = par_.getInset(pos);
@@ -168,6 +173,9 @@ void RowPainter::paintInset(pos_type const pos, LyXFont const & font)
                font;
        pi.ltr_pos = (text_.bidi.level(pos) % 2 == 0);
        pi.erased_ = erased_ || par_.isDeleted(pos);
+#ifdef DEBUG_METRICS
+       int const x1 = int(x_);
+#endif
        bv_.coordCache().insets().add(inset, int(x_), yo_);
        InsetText const * const in = inset->asTextInset();
        // non-wide insets are painted completely. Recursive
@@ -181,6 +189,35 @@ void RowPainter::paintInset(pos_type const pos, LyXFont const & font)
        inset->draw(pi, int(x_), yo_);
        refreshInside = tmp;
        x_ += inset->width();
+#ifdef DEBUG_METRICS
+       Dimension dim;
+       BOOST_ASSERT(text_.maxwidth_ > 0);
+       int const w = text_.maxwidth_ - leftMargin() - text_.rightMargin(*bv_.buffer(), par_);
+       MetricsInfo mi(&bv_, font, w);
+       inset->metrics(mi, dim);
+       if (inset->width() > dim.wid) 
+               lyxerr << "Error: inset " << to_ascii(inset->getInsetName())
+                      << " draw width " << inset->width()
+                      << "> metrics width " << dim.wid << "." << std::endl;
+       if (inset->ascent() > dim.asc) 
+               lyxerr << "Error: inset " << to_ascii(inset->getInsetName())
+                      << " draw ascent " << inset->ascent()
+                      << "> metrics ascent " << dim.asc << "." << std::endl;
+       if (inset->descent() > dim.des) 
+               lyxerr << "Error: inset " << to_ascii(inset->getInsetName())
+                      << " draw ascent " << inset->descent()
+                      << "> metrics descent " << dim.des << "." << std::endl;
+       BOOST_ASSERT(inset->width() <= dim.wid);
+       BOOST_ASSERT(inset->ascent() <= dim.asc);
+       BOOST_ASSERT(inset->descent() <= dim.des);
+       int const x2 = x1 + dim.wid;
+       int const y1 = yo_ + dim.des;
+       int const y2 = yo_ - dim.asc;
+       pi.pain.line(x1, y1, x1, y2, LColor::green);
+       pi.pain.line(x1, y1, x2, y1, LColor::green);
+       pi.pain.line(x2, y1, x2, y2, LColor::green);
+       pi.pain.line(x1, y2, x2, y2, LColor::green);
+#endif
 }