[Kst] extragear/graphics/kst/kst

George Staikos staikos at kde.org
Thu Oct 6 17:51:11 CEST 2005


SVN commit 467856 by staikos:

cache the font metrics and remove an if() from common called methods


 M  +14 -23    labelrenderer.h  


--- trunk/extragear/graphics/kst/kst/labelrenderer.h #467855:467856
@@ -29,12 +29,7 @@
     x = y = xMax = xStart = 0;
     ascent = descent = 0;
     precision = 8;
-    if (p) {
-      p->setFont(QFont(fontName, fontSize));
-    } else {
-      _font = QFont(fontName, fontSize);
-      _fm = QFontMetrics(_font);
-    }
+    setFont(QFont(fontName, fontSize));
   }
 
   inline const QFont& font() const {
@@ -48,34 +43,28 @@
   inline void setFont(const QFont& f) {
     if (p) {
       p->setFont(f);
+      _ascent = p->fontMetrics().ascent();
+      _descent = p->fontMetrics().descent();
+      _height = p->fontMetrics().height();
     } else {
       _font = f;
       _fm = QFontMetrics(_font);
+      _ascent = _fm.ascent();
+      _descent = _fm.descent();
+      _height = _fm.height();
     }
   }
 
   inline int fontAscent() const {
-    if (p) {
-      return p->fontMetrics().ascent();
-    } else {
-      return _fm.ascent();
-    }
+    return _ascent;
   }
 
   inline int fontDescent() const {
-    if (p) {
-      return p->fontMetrics().descent();
-    } else {
-      return _fm.descent();
-    }
+    return _descent;
   }
 
   inline int fontHeight() const {
-    if (p) {
-      return p->fontMetrics().height();
-    } else {
-      return _fm.height();
-    }
+    return _height;
   }
 
   inline int fontWidth(const QString& txt) const {
@@ -96,8 +85,10 @@
   int precision;
   
   private:
-  QFont _font;
-  QFontMetrics _fm;
+    QFont _font;
+    QFontMetrics _fm;
+    int _ascent, _descent, _height; // caches to avoid performance problem
+                                    // with QFont*
 };
 
 


More information about the Kst mailing list