[Kst] kdeextragear-2/kst/kst

George Staikos staikos at kde.org
Tue Apr 20 17:55:42 CEST 2004


CVS commit by staikos: 

store the ascent information, fix computation of it, and therefore position the
label properly in the buffer


  M +15 -9     kstviewlabel.cpp   1.7
  M +1 -1      kstviewlabel.h   1.6


--- kdeextragear-2/kst/kst/kstviewlabel.cpp  #1.6:1.7
@@ -117,5 +117,5 @@ enum VOffset { None = 0, Up = 1, Down = 
 
 struct LabelChunk {
-  LabelChunk(LabelChunk *parent) : next(0L), group(false), voffset(None) {
+  LabelChunk(LabelChunk *parent) : next(0L), symbol(false), group(false), voffset(None) {
     if (parent) {  // attach and inherit
       parent->next = this;
@@ -405,15 +405,16 @@ void KstViewLabel::drawToBuffer(LabelChu
   }
 
+  int descent = _textHeight - 1 - _ascent;
   switch (KST_JUSTIFY_V(_justify)) {
     case KST_JUSTIFY_V_BOTTOM:
-        y = size().height();
+        y = size().height() - descent;
       break;
     case KST_JUSTIFY_V_CENTER:
-        y = (size().height() + _textHeight) / 2;
+        y = (size().height() + _textHeight) / 2 - descent;
       break;
     case KST_JUSTIFY_V_NONE:
     case KST_JUSTIFY_V_TOP:
     default:
-        y = _textHeight;
+        y = _textHeight - descent;
       break;
   }
@@ -433,4 +434,5 @@ void KstViewLabel::drawToBuffer(LabelChu
         f.setPointSize(fc->size);
         p.setFont(f);
+        size = fc->size;
         y = fc->y;
         delete fc;
@@ -438,5 +440,5 @@ void KstViewLabel::drawToBuffer(LabelChu
     } else {
       FontChange *fc = new FontChange;
-      fc->size = p.font().pointSize();
+      fc->size = size;
       fc->y = y;
       fstack.push(fc);
@@ -481,4 +483,5 @@ void KstViewLabel::computeTextSize(Label
         FontChange *fc = fstack.pop();
         fnt.setPointSize(fc->size);
+        size = fc->size;
         y = fc->y;
         delete fc;
@@ -486,5 +489,5 @@ void KstViewLabel::computeTextSize(Label
     } else {
       FontChange *fc = new FontChange;
-      fc->size = fnt.pointSize();
+      fc->size = size;
       fc->y = y;
       fstack.push(fc);
@@ -508,13 +511,16 @@ void KstViewLabel::computeTextSize(Label
 
     _textWidth += fm.width(fi->text);
-    asc = QMAX(asc, y + fm.ascent());
-    des = QMAX(des, fm.descent() - y);
+    asc = QMAX(asc, - y + fm.ascent());
+    if (- y - fm.descent() < 0) {
+      des = QMAX(des, fm.descent() + y);
+    }
 
     fi = fi->next;
   }
 
+  _ascent = asc;
   _textHeight = 1 + asc + des;
 
-  kdDebug() << "Computed label width=" << _textWidth << " height=" << _textHeight << endl;
+  kdDebug() << "Computed label width=" << _textWidth << " height=" << _textHeight << " (asc,des)=" << asc << "," << des << endl;
 }
 

--- kdeextragear-2/kst/kst/kstviewlabel.h  #1.5:1.6
@@ -89,5 +89,5 @@ class KstViewLabel : public KstBorderedV
     bool _interpret : 1;
     int _fontSize : 6;
-    int _textWidth, _textHeight;
+    int _textWidth, _textHeight, _ascent;
     KstJustifyType _justify;
     KstBackBuffer _backBuffer;





More information about the Kst mailing list