[Kst] kdeextragear-2/kst/kst
Andrew Walker
arwalker at sumusltd.com
Wed Dec 31 21:15:19 CET 2003
CVS commit by arwalker:
Provide better determination of the bounding rect of a text label, by taking into account any superscripts and/or subscripts
M +34 -6 kstlabel.cpp 1.22
--- kdeextragear-2/kst/kst/kstlabel.cpp #1.21:1.22
@@ -83,6 +83,7 @@ void KstLabel::setJustification(KstJusti
int KstLabel::width(QPainter &p) {
// FIXME: this is still expensive.
- if (Width < 0)
+ if (Width < 0) {
draw(p, 0, 0, false); // Do a dummy draw to evaluate the width
+ }
return int(Width);
}
@@ -131,4 +132,6 @@ void KstLabel::draw(QPainter &p, int px,
double x;
double y;
+ double y_upper;
+ double y_lower;
double x0;
int i_g;
@@ -226,4 +229,6 @@ void KstLabel::draw(QPainter &p, int px,
}
+ y_upper = y;
+ y_lower = y;
x0 = x;
processedText = Text;
@@ -318,5 +323,12 @@ void KstLabel::draw(QPainter &p, int px,
p.drawText(int(x),int(y + fP[i_fp].dy), str);
}
+
x += p.fontMetrics().width(str);
+ if( y + fP[i_fp].dy - (double)p.fontMetrics().ascent() < y_upper ) {
+ y_upper = y + fP[i_fp].dy - (double)p.fontMetrics().ascent();
+ }
+ if( y + fP[i_fp].dy + (double)p.fontMetrics().descent() > y_lower ) {
+ y_lower = y + fP[i_fp].dy + (double)p.fontMetrics().descent();
+ }
} else {
if (processedText.find( "it", i+1, FALSE ) == (int)i+1 ) {
@@ -354,4 +366,11 @@ void KstLabel::draw(QPainter &p, int px,
}
x += p.fontMetrics().width(strOut);
+ x += p.fontMetrics().width(strOut);
+ if( y + fP[i_fp].dy - (double)p.fontMetrics().ascent() < y_upper ) {
+ y_upper = y + fP[i_fp].dy - (double)p.fontMetrics().ascent();
+ }
+ if( y + fP[i_fp].dy + (double)p.fontMetrics().descent() > y_lower ) {
+ y_lower = y + fP[i_fp].dy + (double)p.fontMetrics().descent();
+ }
strOut = QString::null;
}
@@ -374,5 +393,12 @@ void KstLabel::draw(QPainter &p, int px,
p.drawText(int(x),int(y + fP[i_fp].dy), strOut);
}
+
x += p.fontMetrics().width(strOut);
+ if( y + fP[i_fp].dy - (double)p.fontMetrics().ascent() < y_upper ) {
+ y_upper = y + fP[i_fp].dy - (double)p.fontMetrics().ascent();
+ }
+ if( y + fP[i_fp].dy + (double)p.fontMetrics().descent() > y_lower ) {
+ y_lower = y + fP[i_fp].dy + (double)p.fontMetrics().descent();
+ }
}
@@ -381,5 +407,7 @@ void KstLabel::draw(QPainter &p, int px,
if( doDraw ) {
- extents.setRect((int)(px + x0), (int)(py + y-h), (int)Width, h);
+ extents.setRect((int)(px + x0), (int)(py + y_upper),
+ (int)Width, (int)(y_lower - y_upper + 1));
+ extents.normalize( );
}
}
More information about the Kst
mailing list