summaryrefslogtreecommitdiffstats
path: root/src/gui/text
diff options
context:
space:
mode:
authorKonstantin Ritt <ritt.ks@gmail.com>2014-03-06 12:02:25 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-03-10 15:05:01 +0100
commit11eb9d37dc191b6e71c903e4f7f4d2da579e7df5 (patch)
treef2f5695fe82251000b969410bb4860a5ffdecc0d /src/gui/text
parentca280bfe3bc551f814d59d25079e098798fbdad7 (diff)
Use QStringIterator instead of homebrew
Task-number: QTBUG-15664 Change-Id: I1ed3eb04ddd822e57a4d993af656dfe283f3af1a Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/gui/text')
-rw-r--r--src/gui/text/qfontengine.cpp11
-rw-r--r--src/gui/text/qfontengine_ft.cpp21
-rw-r--r--src/gui/text/qfontengine_qpa.cpp22
-rw-r--r--src/gui/text/qharfbuzzng.cpp14
4 files changed, 24 insertions, 44 deletions
diff --git a/src/gui/text/qfontengine.cpp b/src/gui/text/qfontengine.cpp
index c6674a1b12..a72ac23418 100644
--- a/src/gui/text/qfontengine.cpp
+++ b/src/gui/text/qfontengine.cpp
@@ -1594,10 +1594,10 @@ bool QFontEngineMulti::stringToCMap(const QChar *str, int len,
const_cast<QFontEngineMulti *>(this)->ensureFallbackFamiliesQueried();
int glyph_pos = 0;
- for (int i = 0; i < len; ++i) {
- bool surrogate = (str[i].isHighSurrogate() && i < len-1 && str[i+1].isLowSurrogate());
- uint ucs4 = surrogate ? QChar::surrogateToUcs4(str[i], str[i+1]) : str[i].unicode();
- if (glyphs->glyphs[glyph_pos] == 0 && str[i].category() != QChar::Separator_Line) {
+ QStringIterator it(str, str + len);
+ while (it.hasNext()) {
+ const uint ucs4 = it.peekNext();
+ if (glyphs->glyphs[glyph_pos] == 0 && ucs4 != QChar::LineSeparator) {
for (int x = 1, n = qMin(engines.size(), 256); x < n; ++x) {
if (engines.at(x) == 0 && !shouldLoadFontEngineForCharacter(x, ucs4))
continue;
@@ -1625,8 +1625,7 @@ bool QFontEngineMulti::stringToCMap(const QChar *str, int len,
}
}
- if (surrogate)
- ++i;
+ it.advance();
++glyph_pos;
}
diff --git a/src/gui/text/qfontengine_ft.cpp b/src/gui/text/qfontengine_ft.cpp
index f8b7fc3d5c..11e9ce6c02 100644
--- a/src/gui/text/qfontengine_ft.cpp
+++ b/src/gui/text/qfontengine_ft.cpp
@@ -45,6 +45,7 @@
#include "qvariant.h"
#include "qfontengine_ft_p.h"
#include "private/qimage_p.h"
+#include <private/qstringiterator_p.h>
#ifndef QT_NO_FREETYPE
@@ -1447,16 +1448,6 @@ bool QFontEngineFT::supportsTransformation(const QTransform &transform) const
return transform.type() <= QTransform::TxTranslate;
}
-static inline unsigned int getChar(const QChar *str, int &i, const int len)
-{
- uint ucs4 = str[i].unicode();
- if (str[i].isHighSurrogate() && i < len-1 && str[i+1].isLowSurrogate()) {
- ++i;
- ucs4 = QChar::surrogateToUcs4(ucs4, str[i].unicode());
- }
- return ucs4;
-}
-
void QFontEngineFT::addOutlineToPath(qreal x, qreal y, const QGlyphLayout &glyphs, QPainterPath *path, QTextItem::RenderFlags flags)
{
if (!glyphs.numGlyphs)
@@ -1543,8 +1534,9 @@ bool QFontEngineFT::stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs
int glyph_pos = 0;
if (freetype->symbol_map) {
FT_Face face = freetype->face;
- for ( int i = 0; i < len; ++i ) {
- unsigned int uc = getChar(str, i, len);
+ QStringIterator it(str, str + len);
+ while (it.hasNext()) {
+ uint uc = it.next();
glyphs->glyphs[glyph_pos] = uc < QFreetypeFace::cmapCacheSize ? freetype->cmapCache[uc] : 0;
if ( !glyphs->glyphs[glyph_pos] ) {
// Symbol fonts can have more than one CMAPs, FreeType should take the
@@ -1573,8 +1565,9 @@ bool QFontEngineFT::stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs
}
} else {
FT_Face face = freetype->face;
- for (int i = 0; i < len; ++i) {
- unsigned int uc = getChar(str, i, len);
+ QStringIterator it(str, str + len);
+ while (it.hasNext()) {
+ uint uc = it.next();
glyphs->glyphs[glyph_pos] = uc < QFreetypeFace::cmapCacheSize ? freetype->cmapCache[uc] : 0;
if (!glyphs->glyphs[glyph_pos]) {
{
diff --git a/src/gui/text/qfontengine_qpa.cpp b/src/gui/text/qfontengine_qpa.cpp
index 5a6021fe53..f9ed3c38c1 100644
--- a/src/gui/text/qfontengine_qpa.cpp
+++ b/src/gui/text/qfontengine_qpa.cpp
@@ -45,6 +45,7 @@
#include <QtCore/QFileInfo>
#include <QtCore/QDir>
#include <QtCore/QBuffer>
+#include <QtCore/private/qstringiterator_p.h>
#include <QtGui/private/qpaintengine_raster_p.h>
#include <QtGui/private/qguiapplication_p.h>
@@ -225,17 +226,6 @@ QVariant QFontEngineQPA::extractHeaderField(const uchar *data, HeaderTag request
}
-
-static inline unsigned int getChar(const QChar *str, int &i, const int len)
-{
- uint ucs4 = str[i].unicode();
- if (str[i].isHighSurrogate() && i < len-1 && str[i+1].isLowSurrogate()) {
- ++i;
- ucs4 = QChar::surrogateToUcs4(ucs4, str[i].unicode());
- }
- return ucs4;
-}
-
QFontEngineQPA::QFontEngineQPA(const QFontDef &def, const QByteArray &data)
: QFontEngine(QPF2),
fontData(reinterpret_cast<const uchar *>(data.constData())), dataSize(data.size())
@@ -363,16 +353,18 @@ bool QFontEngineQPA::stringToCMap(const QChar *str, int len, QGlyphLayout *glyph
int glyph_pos = 0;
if (symbol) {
- for (int i = 0; i < len; ++i) {
- unsigned int uc = getChar(str, i, len);
+ QStringIterator it(str, str + len);
+ while (it.hasNext()) {
+ const uint uc = it.next();
glyphs->glyphs[glyph_pos] = getTrueTypeGlyphIndex(cmap, uc);
if(!glyphs->glyphs[glyph_pos] && uc < 0x100)
glyphs->glyphs[glyph_pos] = getTrueTypeGlyphIndex(cmap, uc + 0xf000);
++glyph_pos;
}
} else {
- for (int i = 0; i < len; ++i) {
- unsigned int uc = getChar(str, i, len);
+ QStringIterator it(str, str + len);
+ while (it.hasNext()) {
+ const uint uc = it.next();
glyphs->glyphs[glyph_pos] = getTrueTypeGlyphIndex(cmap, uc);
#if 0 && defined(DEBUG_FONTENGINE)
QChar c(uc);
diff --git a/src/gui/text/qharfbuzzng.cpp b/src/gui/text/qharfbuzzng.cpp
index f7a1d30e6f..1258ea9a78 100644
--- a/src/gui/text/qharfbuzzng.cpp
+++ b/src/gui/text/qharfbuzzng.cpp
@@ -45,6 +45,8 @@
#include <qstring.h>
#include <qvector.h>
+#include <private/qstringiterator_p.h>
+
#include "qfontengine_p.h"
QT_BEGIN_NAMESPACE
@@ -341,16 +343,10 @@ _hb_qt_unicode_decompose_compatibility(hb_unicode_funcs_t * /*ufuncs*/,
const QString normalized = QChar::decomposition(u);
uint outlen = 0;
-
- // ### replace with QCharIterator
- const ushort *p = reinterpret_cast<const ushort *>(normalized.unicode());
- const ushort *const e = p + normalized.size();
- for ( ; p != e; ++p) {
- uint ucs4 = *p;
- if (QChar::isHighSurrogate(ucs4) && p + 1 != e && QChar::isLowSurrogate(p[1]))
- ucs4 = QChar::surrogateToUcs4(ucs4, *++p);
+ QStringIterator it(normalized);
+ while (it.hasNext()) {
Q_ASSERT(outlen < HB_UNICODE_MAX_DECOMPOSITION_LEN);
- decomposed[outlen++] = ucs4;
+ decomposed[outlen++] = it.next();
}
return outlen;