See http://bugzilla.lyx.org/show_bug.cgi?id=2022. The problem is that the
label part is not included in metrics(). A fix is attached. Questions:

- What about the centering problem that Jürgen mentioned?
- Do we want to fix this bug in 1.4.0? (IMO yes)

Attached is also a patch for debugging metrics that may be useful elsewhere
(e.g. it shows that tables have some additional space left and right but
not on top and bottom. Is this intended?)


Georg
Index: src/insets/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/ChangeLog,v
retrieving revision 1.1186
diff -u -p -r1.1186 ChangeLog
--- src/insets/ChangeLog	10 Sep 2005 06:51:54 -0000	1.1186
+++ src/insets/ChangeLog	12 Sep 2005 11:42:21 -0000
@@ -1,3 +1,8 @@
+2005-09-12  Georg Baum  <[EMAIL PROTECTED]>
+
+	* insetvspace.C (metrics): include label text
+	* insetvspace.[Ch] (label): new, needed for the above
+
 2005-08-10  Jürgen Spitzmüller  <[EMAIL PROTECTED]>
 
 	* insetbase.[Ch]: new bool neverIndent() which indicates if
Index: src/insets/insetvspace.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetvspace.C,v
retrieving revision 1.17
diff -u -p -r1.17 insetvspace.C
--- src/insets/insetvspace.C	24 May 2005 10:23:30 -0000	1.17
+++ src/insets/insetvspace.C	12 Sep 2005 11:42:23 -0000
@@ -102,10 +102,21 @@ void InsetVSpace::write(Buffer const &, 
 }
 
 
+string const InsetVSpace::label() const
+{
+	static string const label = _("Vertical Space");
+	return label + " (" + space_.asGUIName() + ')';
+}
+
+
+namespace {
+int const arrow_size = 4;
+}
+
+
 void InsetVSpace::metrics(MetricsInfo & mi, Dimension & dim) const
 {
 	int size = 10;
-	int const arrow_size = 4;
 	int const space_size = space_.inPixels(*mi.base.bv);
 
 	LyXFont font;
@@ -119,7 +130,12 @@ void InsetVSpace::metrics(MetricsInfo & 
 
 	dim.asc = size / 2;
 	dim.des = size / 2;
-	dim.wid = 10 + 2 * ADD_TO_VSPACE_WIDTH;
+	int w = 0;
+	int a = 0;
+	int d = 0;
+	font.decSize();
+	font_metrics::rectText(label(), font, w, a, d);
+	dim.wid = ADD_TO_VSPACE_WIDTH + 2 * arrow_size + 5 + w;
 
 	dim_ = dim;
 }
@@ -127,25 +143,20 @@ void InsetVSpace::metrics(MetricsInfo & 
 
 void InsetVSpace::draw(PainterInfo & pi, int x, int y) const
 {
-	static std::string const label = _("Vertical Space");
-
 	setPosCache(pi, x, y);
 
 	x += ADD_TO_VSPACE_WIDTH;
 
-	int const arrow_size = 4;
 	int const start = y - dim_.asc;
 	int const end   = y + dim_.des;
 
 	// the label to display (if any)
-	string str;
+	string const str = label();
 	// y-values for top arrow
 	int ty1, ty2;
 	// y-values for bottom arrow
 	int by1, by2;
 
-	str = label + " (" + space_.asGUIName() + ")";
-
 	if (space_.kind() == VSpace::VFILL) {
 		ty1 = ty2 = start;
 		by1 = by2 = end;
@@ -171,7 +182,7 @@ void InsetVSpace::draw(PainterInfo & pi,
 	font.setColor(LColor::added_space);
 	font.decSize();
 	font.decSize();
-	font_metrics::rectText(str, font, w, a, d);
+	font_metrics::rectText(label(), font, w, a, d);
 
 	pi.pain.rectText(x + 2 * arrow_size + 5, y + d,
 		       str, font, LColor::none, LColor::none);
Index: src/insets/insetvspace.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetvspace.h,v
retrieving revision 1.9
diff -u -p -r1.9 insetvspace.h
--- src/insets/insetvspace.h	24 Nov 2004 21:58:41 -0000	1.9
+++ src/insets/insetvspace.h	12 Sep 2005 11:42:23 -0000
@@ -56,6 +56,8 @@ protected:
 
 private:
 	virtual std::auto_ptr<InsetBase> doClone() const;
+	///
+	std::string const label() const;
 
 	///
 	VSpace space_;
Index: src/rowpainter.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/rowpainter.C,v
retrieving revision 1.155
diff -u -p -r1.155 rowpainter.C
--- src/rowpainter.C	7 Sep 2005 10:37:00 -0000	1.155
+++ src/rowpainter.C	12 Sep 2005 11:42:15 -0000
@@ -153,10 +153,42 @@ void RowPainter::paintInset(pos_type con
 	pi.base.font = font;
 	pi.ltr_pos = (text_.bidi.level(pos) % 2 == 0);
 	pi.erased_ = erased_ || isDeletedText(par_, pos);
+#ifdef DEBUG_METRICS
+	int const x1 = int(x_);
+#endif
 	theCoords.insets().add(inset, int(x_), yo_);
 	inset->drawSelection(pi, int(x_), yo_);
 	inset->draw(pi, int(x_), yo_);
 	x_ += inset->width();
+#ifdef DEBUG_METRICS
+	Dimension dim;
+	BOOST_ASSERT(text_.maxwidth_ > 0);
+	int const w = text_.maxwidth_ - text_.leftMargin(pit_) - text_.rightMargin(par_);
+	MetricsInfo mi(&bv_, font, w);
+	inset->metrics(mi, dim);
+	if (inset->width() > dim.wid) 
+		lyxerr << "Error: inset " << inset->getInsetName()
+		       << " draw width " << inset->width()
+		       << "> metrics width " << dim.wid << "." << std::endl;
+	if (inset->ascent() > dim.asc) 
+		lyxerr << "Error: inset " << inset->getInsetName()
+		       << " draw ascent " << inset->ascent()
+		       << "> metrics ascent " << dim.asc << "." << std::endl;
+	if (inset->descent() > dim.des) 
+		lyxerr << "Error: inset " << 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
 }
 
 

Reply via email to