From: Abdelrazak Younes Date: Fri, 27 Oct 2006 21:27:03 +0000 (+0000) Subject: * GuiFontMetrics: new metrics(QString) method X-Git-Tag: 1.6.10~12165 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=7f94f08bbe9d380c4d51145d795dc8c760a78be7;p=features.git * GuiFontMetrics: new metrics(QString) method * 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 --- diff --git a/src/frontends/qt4/GuiFontMetrics.C b/src/frontends/qt4/GuiFontMetrics.C index 36fc33dde0..080a3f45c0 100644 --- a/src/frontends/qt4/GuiFontMetrics.C +++ b/src/frontends/qt4/GuiFontMetrics.C @@ -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] == '-') diff --git a/src/frontends/qt4/GuiFontMetrics.h b/src/frontends/qt4/GuiFontMetrics.h index 44ee9c3820..08e6975c6c 100644 --- a/src/frontends/qt4/GuiFontMetrics.h +++ b/src/frontends/qt4/GuiFontMetrics.h @@ -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; diff --git a/src/frontends/qt4/QLPainter.C b/src/frontends/qt4/QLPainter.C index 2423c4b9a7..281365c8eb 100644 --- a/src/frontends/qt4/QLPainter.C +++ b/src/frontends/qt4/QLPainter.C @@ -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); }