diff options
author | Ritt Konstantin <ritt.ks@gmail.com> | 2011-07-22 11:16:41 (GMT) |
---|---|---|
committer | Jiang Jiang <jiang.jiang@nokia.com> | 2011-07-22 11:16:41 (GMT) |
commit | 8ed1f02c0ca4626ddb2e9262aad4459ff3474630 (patch) | |
tree | 4711e9ba5a898fb83f912d20e65e825e10ab312e /src | |
parent | d1f25aad71725b66ddcac52d84999d592ad4d132 (diff) | |
download | Qt-8ed1f02c0ca4626ddb2e9262aad4459ff3474630.zip Qt-8ed1f02c0ca4626ddb2e9262aad4459ff3474630.tar.gz Qt-8ed1f02c0ca4626ddb2e9262aad4459ff3474630.tar.bz2 |
optimize QRawFont::supportsCharacter()
a single UCS-4-encoded codepoint could morph into 1 or 2 UCS-2-encoded codepoints only;
thus, allocating QString just to parse it could be avoided and the well-defined
UCS-4 to UCS-2 arithmetic could be used instead
Merge-request: 1305
Reviewed-by: Jiang Jiang <jiang.jiang@nokia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/text/qrawfont.cpp | 17 | ||||
-rw-r--r-- | src/gui/text/qrawfont.h | 2 |
2 files changed, 15 insertions, 4 deletions
diff --git a/src/gui/text/qrawfont.cpp b/src/gui/text/qrawfont.cpp index 2c60b14..e3e5c57 100644 --- a/src/gui/text/qrawfont.cpp +++ b/src/gui/text/qrawfont.cpp @@ -624,7 +624,7 @@ QList<QFontDatabase::WritingSystem> QRawFont::supportedWritingSystems() const \sa supportedWritingSystems() */ -bool QRawFont::supportsCharacter(const QChar &character) const +bool QRawFont::supportsCharacter(QChar character) const { if (!isValid()) return false; @@ -633,6 +633,7 @@ bool QRawFont::supportsCharacter(const QChar &character) const } /*! + \overload Returns true if the font has a glyph that corresponds to the UCS-4 encoded character \a ucs4. \sa supportedWritingSystems() @@ -642,8 +643,18 @@ bool QRawFont::supportsCharacter(quint32 ucs4) const if (!isValid()) return false; - QString str = QString::fromUcs4(&ucs4, 1); - return d->fontEngine->canRender(str.constData(), str.size()); + QChar str[2]; + int len; + if (!QChar::requiresSurrogates(ucs4)) { + str[0] = QChar(ucs4); + len = 1; + } else { + str[0] = QChar(QChar::highSurrogate(ucs4)); + str[1] = QChar(QChar::lowSurrogate(ucs4)); + len = 2; + } + + return d->fontEngine->canRender(str, len); } // qfontdatabase.cpp diff --git a/src/gui/text/qrawfont.h b/src/gui/text/qrawfont.h index 88ec6cb..d5b5680 100644 --- a/src/gui/text/qrawfont.h +++ b/src/gui/text/qrawfont.h @@ -122,7 +122,7 @@ public: QFont::HintingPreference hintingPreference); bool supportsCharacter(quint32 ucs4) const; - bool supportsCharacter(const QChar &character) const; + bool supportsCharacter(QChar character) const; QList<QFontDatabase::WritingSystem> supportedWritingSystems() const; QByteArray fontTable(const char *tagName) const; |