[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kgraphviewer-devel
Subject:    [kgraphviewer-devel] =?utf-8?q?=5Bkgraphviewer=5D_src/part=3A_opt?=
From:       Milian Wolff <mail () milianw ! de>
Date:       2011-07-15 16:03:01
Message-ID: 20110715160301.8DA12A60A6 () git ! kde ! org
[Download RAW message or body]

Git commit 863cda2aaf84d311e0ed5672b3a6c3125a1608c6 by Milian Wolff.
Committed on 15/07/2011 at 18:03.
Pushed by mwolff into branch 'master'.

optimize: interpolate fontwidth and save calls to slow QFontMetrics::width

already gives a 50% speedup (according to callgrind) for big graphs with lots of text,
as e.g. created by massif-visualizer

M  +9    -4    src/part/canvaselement.cpp     

http://commits.kde.org/kgraphviewer/863cda2aaf84d311e0ed5672b3a6c3125a1608c6

diff --git a/src/part/canvaselement.cpp b/src/part/canvaselement.cpp
index e3d6284..dcbb28e 100644
--- a/src/part/canvaselement.cpp
+++ b/src/part/canvaselement.cpp
@@ -451,13 +451,18 @@ QWidget *widget)
       int fontSize = element()->fontSize();
 //       kDebug() << element()->id() << " initial fontSize " << fontSize;
       m_font->setPointSize(fontSize);
+
       QFontMetrics fm(*m_font);
-      while (fm.width(dro.str) > stringWidthGoal && fontSize > 1)
+      int fontWidth = fm.width(dro.str);
+      while (fontWidth > stringWidthGoal && fontSize > 1)
       {
-        fontSize--;
+        // use floor'ed extrapolated font size
+        fontSize = double(stringWidthGoal) / fontWidth * fontSize;
         m_font->setPointSize(fontSize);
         fm = QFontMetrics(*m_font);
+        fontWidth = fm.width(dro.str);
       }
+
       p->save();
       p->setFont(*m_font);
       QPen pen(m_pen);
@@ -466,8 +471,8 @@ QWidget *widget)
       qreal x = (m_scaleX *
                        (
                          (dro.integers[0])
-                         + (((-dro.integers[2])*(fm.width(dro.str)))/2)
-                         - ( (fm.width(dro.str))/2 )
+                         + (((-dro.integers[2])*(fontWidth))/2)
+                         - ( (fontWidth)/2 )
                        )
                       )
                       + m_xMargin;
_______________________________________________
kgraphviewer-devel mailing list
kgraphviewer-devel@kde.org
https://mail.kde.org/mailman/listinfo/kgraphviewer-devel
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic