* 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
This commit is contained in:
Abdelrazak Younes 2006-10-27 21:27:03 +00:00
parent f43176aebc
commit 7f94f08bbe
3 changed files with 22 additions and 2 deletions

View 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] == '-')

View 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;

View 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);
}