Re: [PATCH] vspace metrics/draw corrections/improvements

2005-09-18 Thread Michael Gerz

Michael Gerz wrote:

if you place the cursor in front of a vspace inset, it is displayed 
way too high.


I had a look at method metrics in insetvspace.C which IMHO is a bit 
confusing (and partially wrong - Why is size set to 10 initially? Why 
do we decrease the font size twice but compute some values in between?)


I cleaned up the code and modified it in such a way that the cursor in 
displayed on the same level as the vspace label.


Jean-Marc, Lars, can I commit it? (Pleease...)


Something strange is going on with space computation :-( I'll come back 
with a better patch latter.


Michael


Re: [PATCH] vspace metrics/draw corrections/improvements

2005-09-18 Thread Michael Gerz

Michael Gerz wrote:

if you place the cursor in front of a vspace inset, it is displayed 
way too high.


I had a look at method "metrics" in insetvspace.C which IMHO is a bit 
confusing (and partially wrong - Why is size set to 10 initially? Why 
do we decrease the font size twice but compute some values in between?)


I cleaned up the code and modified it in such a way that the cursor in 
displayed on the same level as the vspace label.


Jean-Marc, Lars, can I commit it? (Pleease...)


Something strange is going on with space computation :-( I'll come back 
with a better patch latter.


Michael


[PATCH] vspace metrics/draw corrections/improvements

2005-09-16 Thread Michael Gerz

Hello,

if you place the cursor in front of a vspace inset, it is displayed way 
too high.


I had a look at method metrics in insetvspace.C which IMHO is a bit 
confusing (and partially wrong - Why is size set to 10 initially? Why do 
we decrease the font size twice but compute some values in between?)


I cleaned up the code and modified it in such a way that the cursor in 
displayed on the same level as the vspace label.


Jean-Marc, Lars, can I commit it? (Pleease...)

Michael

PS: This was a nice opportunity in order to practice metrics 
computation. I am ready for the rowpainter stuff now :-)
Index: ChangeLog
===
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/ChangeLog,v
retrieving revision 1.1189
diff -u -r1.1189 ChangeLog
--- ChangeLog	16 Sep 2005 10:19:02 -	1.1189
+++ ChangeLog	16 Sep 2005 16:46:17 -
@@ -1,3 +1,8 @@
+2005-09-16  Michael Gerz  [EMAIL PROTECTED]
+
+	* insetvspace.C (metrics): compute ascent and descent in a way that
+	the cursor is placed on the same level as the label text 
+
 2005-09-11  Martin Vermeer  [EMAIL PROTECTED]
 
 	* insettabular.C: fixes bug 1765: multicol cell width on screen not
Index: insetvspace.C
===
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetvspace.C,v
retrieving revision 1.18
diff -u -r1.18 insetvspace.C
--- insetvspace.C	12 Sep 2005 14:57:50 -	1.18
+++ insetvspace.C	16 Sep 2005 16:46:17 -
@@ -116,25 +116,25 @@
 
 void InsetVSpace::metrics(MetricsInfo  mi, Dimension  dim) const
 {
-	int size = 10;
-	int const space_size = space_.inPixels(*mi.base.bv);
-
 	LyXFont font;
 	font.decSize();
-	int const min_size = max(3 * arrow_size, font_metrics::maxHeight(font));
+	font.decSize();
+
+	int height = 3 * arrow_size;
 
-	if (space_.length().len().value()  0.0)
-		size = min_size;
-	else
-		size = max(min_size, space_size);
+	if (space_.length().len().value()  0.0)
+		height = max(height, space_.inPixels(*mi.base.bv));
 
-	dim.asc = size / 2;
-	dim.des = size / 2;
 	int w = 0;
 	int a = 0;
 	int d = 0;
-	font.decSize();
 	font_metrics::rectText(label(), font, w, a, d);
+
+	height = max(height, a * 2 + 1); // one extra pixel at the top
+	height = max(height, d * 2 + 1); // ... and at the bottom
+
+	dim.asc = height / 2 + (a - d) / 2; // align cursor with the
+	dim.des = height - dim.asc; // label text
 	dim.wid = ADD_TO_VSPACE_WIDTH + 2 * arrow_size + 5 + w;
 
 	dim_ = dim;
@@ -150,8 +150,6 @@
 	int const start = y - dim_.asc;
 	int const end   = y + dim_.des;
 
-	// the label to display (if any)
-	string const str = label();
 	// y-values for top arrow
 	int ty1, ty2;
 	// y-values for bottom arrow
@@ -184,8 +182,9 @@
 	font.decSize();
 	font_metrics::rectText(label(), font, w, a, d);
 
-	pi.pain.rectText(x + 2 * arrow_size + 5, y + d,
-		   str, font, LColor::none, LColor::none);
+	pi.pain.rectText(x + 2 * arrow_size + 5, 
+			 start + (end - start) / 2 + (a - d) / 2,
+			 label(), font, LColor::none, LColor::none);
 
 	// top arrow
 	pi.pain.line(x, ty1, midx, ty2, LColor::added_space);


Re: [PATCH] vspace metrics/draw corrections/improvements

2005-09-16 Thread Georg Baum
Michael Gerz wrote:

 Hello,
 
 if you place the cursor in front of a vspace inset, it is displayed way
 too high.

Did you try different vspace values (very large, very small)? I am not sure
whether this behaviour is on purpose or not.

 I had a look at method metrics in insetvspace.C which IMHO is a bit
 confusing (and partially wrong - Why is size set to 10 initially?

This is not needed, but does no harm either.

 Why do 
 we decrease the font size twice but compute some values in between?)

Because it was only one step until recently. When I included the text width
in metrics I did change the original code as little as possible because I
did not want to dig in the details of the vertical metrics.


Georg



Re: [PATCH] vspace metrics/draw corrections/improvements

2005-09-16 Thread Michael Gerz

Georg Baum wrote:


if you place the cursor in front of a vspace inset, it is displayed way
too high.
   


Did you try different vspace values (very large, very small)? I am not sure
whether this behaviour is on purpose or not.
 

Yes, I did. The LyX cursor is determined by the font size of the 
paragraph; its vertical bar is drawn from maximum ascent to maximum 
descent. To make vspace insets look good, their relative position to the 
baseline must be defined properly. This is what the patch does.



This is not needed, but does no harm either.
 


I know.

Why do 
we decrease the font size twice but compute some values in between?)
   


Because it was only one step until recently. When I included the text width
in metrics I did change the original code as little as possible because I
did not want to dig in the details of the vertical metrics.
 

Aha! Anyway, I hope that the new code is a bit clearer. After all there 
is no magic in it.


Michael


[PATCH] vspace metrics/draw corrections/improvements

2005-09-16 Thread Michael Gerz

Hello,

if you place the cursor in front of a vspace inset, it is displayed way 
too high.


I had a look at method "metrics" in insetvspace.C which IMHO is a bit 
confusing (and partially wrong - Why is size set to 10 initially? Why do 
we decrease the font size twice but compute some values in between?)


I cleaned up the code and modified it in such a way that the cursor in 
displayed on the same level as the vspace label.


Jean-Marc, Lars, can I commit it? (Pleease...)

Michael

PS: This was a nice opportunity in order to practice metrics 
computation. I am ready for the rowpainter stuff now :-)
Index: ChangeLog
===
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/ChangeLog,v
retrieving revision 1.1189
diff -u -r1.1189 ChangeLog
--- ChangeLog	16 Sep 2005 10:19:02 -	1.1189
+++ ChangeLog	16 Sep 2005 16:46:17 -
@@ -1,3 +1,8 @@
+2005-09-16  Michael Gerz  <[EMAIL PROTECTED]>
+
+	* insetvspace.C (metrics): compute ascent and descent in a way that
+	the cursor is placed on the same level as the label text 
+
 2005-09-11  Martin Vermeer  <[EMAIL PROTECTED]>
 
 	* insettabular.C: fixes bug 1765: multicol cell width on screen not
Index: insetvspace.C
===
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetvspace.C,v
retrieving revision 1.18
diff -u -r1.18 insetvspace.C
--- insetvspace.C	12 Sep 2005 14:57:50 -	1.18
+++ insetvspace.C	16 Sep 2005 16:46:17 -
@@ -116,25 +116,25 @@
 
 void InsetVSpace::metrics(MetricsInfo & mi, Dimension & dim) const
 {
-	int size = 10;
-	int const space_size = space_.inPixels(*mi.base.bv);
-
 	LyXFont font;
 	font.decSize();
-	int const min_size = max(3 * arrow_size, font_metrics::maxHeight(font));
+	font.decSize();
+
+	int height = 3 * arrow_size;
 
-	if (space_.length().len().value() < 0.0)
-		size = min_size;
-	else
-		size = max(min_size, space_size);
+	if (space_.length().len().value() > 0.0)
+		height = max(height, space_.inPixels(*mi.base.bv));
 
-	dim.asc = size / 2;
-	dim.des = size / 2;
 	int w = 0;
 	int a = 0;
 	int d = 0;
-	font.decSize();
 	font_metrics::rectText(label(), font, w, a, d);
+
+	height = max(height, a * 2 + 1); // one extra pixel at the top
+	height = max(height, d * 2 + 1); // ... and at the bottom
+
+	dim.asc = height / 2 + (a - d) / 2; // align cursor with the
+	dim.des = height - dim.asc; // label text
 	dim.wid = ADD_TO_VSPACE_WIDTH + 2 * arrow_size + 5 + w;
 
 	dim_ = dim;
@@ -150,8 +150,6 @@
 	int const start = y - dim_.asc;
 	int const end   = y + dim_.des;
 
-	// the label to display (if any)
-	string const str = label();
 	// y-values for top arrow
 	int ty1, ty2;
 	// y-values for bottom arrow
@@ -184,8 +182,9 @@
 	font.decSize();
 	font_metrics::rectText(label(), font, w, a, d);
 
-	pi.pain.rectText(x + 2 * arrow_size + 5, y + d,
-		   str, font, LColor::none, LColor::none);
+	pi.pain.rectText(x + 2 * arrow_size + 5, 
+			 start + (end - start) / 2 + (a - d) / 2,
+			 label(), font, LColor::none, LColor::none);
 
 	// top arrow
 	pi.pain.line(x, ty1, midx, ty2, LColor::added_space);


Re: [PATCH] vspace metrics/draw corrections/improvements

2005-09-16 Thread Georg Baum
Michael Gerz wrote:

> Hello,
> 
> if you place the cursor in front of a vspace inset, it is displayed way
> too high.

Did you try different vspace values (very large, very small)? I am not sure
whether this behaviour is on purpose or not.

> I had a look at method "metrics" in insetvspace.C which IMHO is a bit
> confusing (and partially wrong - Why is size set to 10 initially?

This is not needed, but does no harm either.

> Why do 
> we decrease the font size twice but compute some values in between?)

Because it was only one step until recently. When I included the text width
in metrics I did change the original code as little as possible because I
did not want to dig in the details of the vertical metrics.


Georg



Re: [PATCH] vspace metrics/draw corrections/improvements

2005-09-16 Thread Michael Gerz

Georg Baum wrote:


if you place the cursor in front of a vspace inset, it is displayed way
too high.
   


Did you try different vspace values (very large, very small)? I am not sure
whether this behaviour is on purpose or not.
 

Yes, I did. The LyX cursor is determined by the font size of the 
paragraph; its vertical bar is drawn from maximum ascent to maximum 
descent. To make vspace insets look good, their relative position to the 
baseline must be defined properly. This is what the patch does.



This is not needed, but does no harm either.
 


I know.

Why do 
we decrease the font size twice but compute some values in between?)
   


Because it was only one step until recently. When I included the text width
in metrics I did change the original code as little as possible because I
did not want to dig in the details of the vertical metrics.
 

Aha! Anyway, I hope that the new code is a bit clearer. After all there 
is no magic in it.


Michael