]> git.lyx.org Git - features.git/commitdiff
* GuiFontMetrics: new metrics(QString) method
authorAbdelrazak Younes <younes@lyx.org>
Fri, 27 Oct 2006 21:27:03 +0000 (21:27 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Fri, 27 Oct 2006 21:27:03 +0000 (21:27 +0000)
* QLPainter::paintText(): use GuiFontMetrics::metrics(QString) to avoid an ucs4 to QString conversion.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15584 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/GuiFontMetrics.C
src/frontends/qt4/GuiFontMetrics.h
src/frontends/qt4/QLPainter.C

index 36fc33dde0b2cb22cbb4e1130d303bacad65cc54..080a3f45c09561025e61f2588d9eeb02f5da6c0b 100644 (file)
@@ -134,6 +134,24 @@ int GuiFontMetrics::width(char_type const * s, size_t ls) const
 }
 
 
+int GuiFontMetrics::width(QString const & ucs2) const
+{
+       int const ls = ucs2.size();
+       if (ls == 1 && !smallcaps_shape_) {
+               return width(ucs2[0].unicode());
+       }
+
+       if (smallcaps_shape_)
+               return smallcapsWidth(ucs2);
+
+       int w = 0;
+       for (int i = 0; i < ls; ++i)
+               w += width(ucs2[i].unicode());
+
+       return w;
+}
+
+
 int GuiFontMetrics::signedWidth(docstring const & s) const
 {
        if (s[0] == '-')
index 44ee9c38205a06fc89c837f80a89ce44b6c90047..08e6975c6cbb181509c106c90a63888060ec8a15 100644 (file)
@@ -53,6 +53,8 @@ public:
                int & width,
                int & ascent,
                int & descent) const;
+       ///
+       int width(QString const & str) const;
 
 private:
        int smallcapsWidth(QString const & s) const;
index 2423c4b9a721908efdf20aac75bbd513558a7c4f..281365c8ebed584322e2a2b70179f0685764f7d6 100644 (file)
@@ -14,6 +14,7 @@
 #include "QLPainter.h"
 
 #include "GuiApplication.h"
+#include "GuiFontMetrics.h"
 #include "GuiWorkArea.h"
 #include "QLImage.h"
 
@@ -24,7 +25,6 @@
 #include "language.h"
 #include "LColor.h"
 
-#include "frontends/FontMetrics.h"
 
 #include "support/unicode.h"
 
@@ -245,7 +245,7 @@ int QLPainter::text(int x, int y, char_type const * s, size_t ls,
                // Here we use the font width cache instead of
                //   textwidth = fontMetrics().width(str);
                // because the above is awfully expensive on MacOSX
-               textwidth = guiApp->guiFontLoader().metrics(f).width(s, ls);
+               textwidth = fi.metrics->width(str);
        } else {
                textwidth = smallCapsText(x, y, str, f);
        }