Use QStringIterator instead of homebrew
Task-number: QTBUG-15664 Change-Id: I1ed3eb04ddd822e57a4d993af656dfe283f3af1a Reviewed-by: Lars Knoll <lars.knoll@digia.com>
This commit is contained in:
parent
ca280bfe3b
commit
11eb9d37dc
@ -1594,10 +1594,10 @@ bool QFontEngineMulti::stringToCMap(const QChar *str, int len,
|
|||||||
|
|
||||||
const_cast<QFontEngineMulti *>(this)->ensureFallbackFamiliesQueried();
|
const_cast<QFontEngineMulti *>(this)->ensureFallbackFamiliesQueried();
|
||||||
int glyph_pos = 0;
|
int glyph_pos = 0;
|
||||||
for (int i = 0; i < len; ++i) {
|
QStringIterator it(str, str + len);
|
||||||
bool surrogate = (str[i].isHighSurrogate() && i < len-1 && str[i+1].isLowSurrogate());
|
while (it.hasNext()) {
|
||||||
uint ucs4 = surrogate ? QChar::surrogateToUcs4(str[i], str[i+1]) : str[i].unicode();
|
const uint ucs4 = it.peekNext();
|
||||||
if (glyphs->glyphs[glyph_pos] == 0 && str[i].category() != QChar::Separator_Line) {
|
if (glyphs->glyphs[glyph_pos] == 0 && ucs4 != QChar::LineSeparator) {
|
||||||
for (int x = 1, n = qMin(engines.size(), 256); x < n; ++x) {
|
for (int x = 1, n = qMin(engines.size(), 256); x < n; ++x) {
|
||||||
if (engines.at(x) == 0 && !shouldLoadFontEngineForCharacter(x, ucs4))
|
if (engines.at(x) == 0 && !shouldLoadFontEngineForCharacter(x, ucs4))
|
||||||
continue;
|
continue;
|
||||||
@ -1625,8 +1625,7 @@ bool QFontEngineMulti::stringToCMap(const QChar *str, int len,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (surrogate)
|
it.advance();
|
||||||
++i;
|
|
||||||
++glyph_pos;
|
++glyph_pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,6 +45,7 @@
|
|||||||
#include "qvariant.h"
|
#include "qvariant.h"
|
||||||
#include "qfontengine_ft_p.h"
|
#include "qfontengine_ft_p.h"
|
||||||
#include "private/qimage_p.h"
|
#include "private/qimage_p.h"
|
||||||
|
#include <private/qstringiterator_p.h>
|
||||||
|
|
||||||
#ifndef QT_NO_FREETYPE
|
#ifndef QT_NO_FREETYPE
|
||||||
|
|
||||||
@ -1447,16 +1448,6 @@ bool QFontEngineFT::supportsTransformation(const QTransform &transform) const
|
|||||||
return transform.type() <= QTransform::TxTranslate;
|
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)
|
void QFontEngineFT::addOutlineToPath(qreal x, qreal y, const QGlyphLayout &glyphs, QPainterPath *path, QTextItem::RenderFlags flags)
|
||||||
{
|
{
|
||||||
if (!glyphs.numGlyphs)
|
if (!glyphs.numGlyphs)
|
||||||
@ -1543,8 +1534,9 @@ bool QFontEngineFT::stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs
|
|||||||
int glyph_pos = 0;
|
int glyph_pos = 0;
|
||||||
if (freetype->symbol_map) {
|
if (freetype->symbol_map) {
|
||||||
FT_Face face = freetype->face;
|
FT_Face face = freetype->face;
|
||||||
for ( int i = 0; i < len; ++i ) {
|
QStringIterator it(str, str + len);
|
||||||
unsigned int uc = getChar(str, i, len);
|
while (it.hasNext()) {
|
||||||
|
uint uc = it.next();
|
||||||
glyphs->glyphs[glyph_pos] = uc < QFreetypeFace::cmapCacheSize ? freetype->cmapCache[uc] : 0;
|
glyphs->glyphs[glyph_pos] = uc < QFreetypeFace::cmapCacheSize ? freetype->cmapCache[uc] : 0;
|
||||||
if ( !glyphs->glyphs[glyph_pos] ) {
|
if ( !glyphs->glyphs[glyph_pos] ) {
|
||||||
// Symbol fonts can have more than one CMAPs, FreeType should take the
|
// 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 {
|
} else {
|
||||||
FT_Face face = freetype->face;
|
FT_Face face = freetype->face;
|
||||||
for (int i = 0; i < len; ++i) {
|
QStringIterator it(str, str + len);
|
||||||
unsigned int uc = getChar(str, i, len);
|
while (it.hasNext()) {
|
||||||
|
uint uc = it.next();
|
||||||
glyphs->glyphs[glyph_pos] = uc < QFreetypeFace::cmapCacheSize ? freetype->cmapCache[uc] : 0;
|
glyphs->glyphs[glyph_pos] = uc < QFreetypeFace::cmapCacheSize ? freetype->cmapCache[uc] : 0;
|
||||||
if (!glyphs->glyphs[glyph_pos]) {
|
if (!glyphs->glyphs[glyph_pos]) {
|
||||||
{
|
{
|
||||||
|
@ -45,6 +45,7 @@
|
|||||||
#include <QtCore/QFileInfo>
|
#include <QtCore/QFileInfo>
|
||||||
#include <QtCore/QDir>
|
#include <QtCore/QDir>
|
||||||
#include <QtCore/QBuffer>
|
#include <QtCore/QBuffer>
|
||||||
|
#include <QtCore/private/qstringiterator_p.h>
|
||||||
|
|
||||||
#include <QtGui/private/qpaintengine_raster_p.h>
|
#include <QtGui/private/qpaintengine_raster_p.h>
|
||||||
#include <QtGui/private/qguiapplication_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)
|
QFontEngineQPA::QFontEngineQPA(const QFontDef &def, const QByteArray &data)
|
||||||
: QFontEngine(QPF2),
|
: QFontEngine(QPF2),
|
||||||
fontData(reinterpret_cast<const uchar *>(data.constData())), dataSize(data.size())
|
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;
|
int glyph_pos = 0;
|
||||||
if (symbol) {
|
if (symbol) {
|
||||||
for (int i = 0; i < len; ++i) {
|
QStringIterator it(str, str + len);
|
||||||
unsigned int uc = getChar(str, i, len);
|
while (it.hasNext()) {
|
||||||
|
const uint uc = it.next();
|
||||||
glyphs->glyphs[glyph_pos] = getTrueTypeGlyphIndex(cmap, uc);
|
glyphs->glyphs[glyph_pos] = getTrueTypeGlyphIndex(cmap, uc);
|
||||||
if(!glyphs->glyphs[glyph_pos] && uc < 0x100)
|
if(!glyphs->glyphs[glyph_pos] && uc < 0x100)
|
||||||
glyphs->glyphs[glyph_pos] = getTrueTypeGlyphIndex(cmap, uc + 0xf000);
|
glyphs->glyphs[glyph_pos] = getTrueTypeGlyphIndex(cmap, uc + 0xf000);
|
||||||
++glyph_pos;
|
++glyph_pos;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < len; ++i) {
|
QStringIterator it(str, str + len);
|
||||||
unsigned int uc = getChar(str, i, len);
|
while (it.hasNext()) {
|
||||||
|
const uint uc = it.next();
|
||||||
glyphs->glyphs[glyph_pos] = getTrueTypeGlyphIndex(cmap, uc);
|
glyphs->glyphs[glyph_pos] = getTrueTypeGlyphIndex(cmap, uc);
|
||||||
#if 0 && defined(DEBUG_FONTENGINE)
|
#if 0 && defined(DEBUG_FONTENGINE)
|
||||||
QChar c(uc);
|
QChar c(uc);
|
||||||
|
@ -45,6 +45,8 @@
|
|||||||
#include <qstring.h>
|
#include <qstring.h>
|
||||||
#include <qvector.h>
|
#include <qvector.h>
|
||||||
|
|
||||||
|
#include <private/qstringiterator_p.h>
|
||||||
|
|
||||||
#include "qfontengine_p.h"
|
#include "qfontengine_p.h"
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
@ -341,16 +343,10 @@ _hb_qt_unicode_decompose_compatibility(hb_unicode_funcs_t * /*ufuncs*/,
|
|||||||
const QString normalized = QChar::decomposition(u);
|
const QString normalized = QChar::decomposition(u);
|
||||||
|
|
||||||
uint outlen = 0;
|
uint outlen = 0;
|
||||||
|
QStringIterator it(normalized);
|
||||||
// ### replace with QCharIterator
|
while (it.hasNext()) {
|
||||||
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);
|
|
||||||
Q_ASSERT(outlen < HB_UNICODE_MAX_DECOMPOSITION_LEN);
|
Q_ASSERT(outlen < HB_UNICODE_MAX_DECOMPOSITION_LEN);
|
||||||
decomposed[outlen++] = ucs4;
|
decomposed[outlen++] = it.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
return outlen;
|
return outlen;
|
||||||
|
@ -65,6 +65,7 @@
|
|||||||
#include <QtCore/qmath.h>
|
#include <QtCore/qmath.h>
|
||||||
#include <QtCore/QThreadStorage>
|
#include <QtCore/QThreadStorage>
|
||||||
#include <QtCore/private/qsystemlibrary_p.h>
|
#include <QtCore/private/qsystemlibrary_p.h>
|
||||||
|
#include <QtCore/private/qstringiterator_p.h>
|
||||||
|
|
||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
|
|
||||||
@ -205,47 +206,37 @@ void QWindowsFontEngine::getCMap()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ### Qt 5.1: replace with QStringIterator
|
|
||||||
inline unsigned int getChar(const QChar *str, int &i, const int len)
|
|
||||||
{
|
|
||||||
uint uc = str[i].unicode();
|
|
||||||
if (QChar::isHighSurrogate(uc) && i < len-1) {
|
|
||||||
uint low = str[i+1].unicode();
|
|
||||||
if (QChar::isLowSurrogate(low)) {
|
|
||||||
uc = QChar::surrogateToUcs4(uc, low);
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return uc;
|
|
||||||
}
|
|
||||||
|
|
||||||
int QWindowsFontEngine::getGlyphIndexes(const QChar *str, int numChars, QGlyphLayout *glyphs) const
|
int QWindowsFontEngine::getGlyphIndexes(const QChar *str, int numChars, QGlyphLayout *glyphs) const
|
||||||
{
|
{
|
||||||
int i = 0;
|
|
||||||
int glyph_pos = 0;
|
int glyph_pos = 0;
|
||||||
{
|
{
|
||||||
#if defined(Q_OS_WINCE)
|
#if defined(Q_OS_WINCE)
|
||||||
{
|
{
|
||||||
#else
|
#else
|
||||||
if (symbol) {
|
if (symbol) {
|
||||||
for (; i < numChars; ++i, ++glyph_pos) {
|
QStringIterator it(str, str + numChars);
|
||||||
unsigned int uc = getChar(str, i, numChars);
|
while (it.hasNext()) {
|
||||||
|
const uint uc = it.next();
|
||||||
glyphs->glyphs[glyph_pos] = getTrueTypeGlyphIndex(cmap, uc);
|
glyphs->glyphs[glyph_pos] = getTrueTypeGlyphIndex(cmap, uc);
|
||||||
if(!glyphs->glyphs[glyph_pos] && uc < 0x100)
|
if(!glyphs->glyphs[glyph_pos] && uc < 0x100)
|
||||||
glyphs->glyphs[glyph_pos] = getTrueTypeGlyphIndex(cmap, uc + 0xf000);
|
glyphs->glyphs[glyph_pos] = getTrueTypeGlyphIndex(cmap, uc + 0xf000);
|
||||||
|
++glyph_pos;
|
||||||
}
|
}
|
||||||
} else if (ttf) {
|
} else if (ttf) {
|
||||||
for (; i < numChars; ++i, ++glyph_pos) {
|
QStringIterator it(str, str + numChars);
|
||||||
unsigned int uc = getChar(str, i, numChars);
|
while (it.hasNext()) {
|
||||||
|
const uint uc = it.next();
|
||||||
glyphs->glyphs[glyph_pos] = getTrueTypeGlyphIndex(cmap, uc);
|
glyphs->glyphs[glyph_pos] = getTrueTypeGlyphIndex(cmap, uc);
|
||||||
|
++glyph_pos;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
#endif
|
#endif
|
||||||
wchar_t first = tm.tmFirstChar;
|
wchar_t first = tm.tmFirstChar;
|
||||||
wchar_t last = tm.tmLastChar;
|
wchar_t last = tm.tmLastChar;
|
||||||
|
|
||||||
for (; i < numChars; ++i, ++glyph_pos) {
|
QStringIterator it(str, str + numChars);
|
||||||
uint uc = getChar(str, i, numChars);
|
while (it.hasNext()) {
|
||||||
|
const uint uc = it.next();
|
||||||
if (
|
if (
|
||||||
#ifdef Q_WS_WINCE
|
#ifdef Q_WS_WINCE
|
||||||
tm.tmFirstChar > 60000 ||
|
tm.tmFirstChar > 60000 ||
|
||||||
@ -254,6 +245,7 @@ int QWindowsFontEngine::getGlyphIndexes(const QChar *str, int numChars, QGlyphLa
|
|||||||
glyphs->glyphs[glyph_pos] = uc;
|
glyphs->glyphs[glyph_pos] = uc;
|
||||||
else
|
else
|
||||||
glyphs->glyphs[glyph_pos] = 0;
|
glyphs->glyphs[glyph_pos] = 0;
|
||||||
|
++glyph_pos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,6 +53,7 @@
|
|||||||
#include <QtCore/QSettings>
|
#include <QtCore/QSettings>
|
||||||
#include <QtCore/QtEndian>
|
#include <QtCore/QtEndian>
|
||||||
#include <QtCore/QVarLengthArray>
|
#include <QtCore/QVarLengthArray>
|
||||||
|
#include <private/qstringiterator_p.h>
|
||||||
|
|
||||||
#include <dwrite.h>
|
#include <dwrite.h>
|
||||||
#include <d2d1.h>
|
#include <d2d1.h>
|
||||||
@ -314,20 +315,6 @@ glyph_t QWindowsFontEngineDirectWrite::glyphIndex(uint ucs4) const
|
|||||||
return glyphIndex;
|
return glyphIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ### Qt 5.1: replace with QStringIterator
|
|
||||||
inline unsigned int getChar(const QChar *str, int &i, const int len)
|
|
||||||
{
|
|
||||||
uint uc = str[i].unicode();
|
|
||||||
if (QChar::isHighSurrogate(uc) && i < len-1) {
|
|
||||||
uint low = str[i+1].unicode();
|
|
||||||
if (QChar::isLowSurrogate(low)) {
|
|
||||||
uc = QChar::surrogateToUcs4(uc, low);
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return uc;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QWindowsFontEngineDirectWrite::stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs,
|
bool QWindowsFontEngineDirectWrite::stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs,
|
||||||
int *nglyphs, QFontEngine::ShaperFlags flags) const
|
int *nglyphs, QFontEngine::ShaperFlags flags) const
|
||||||
{
|
{
|
||||||
@ -339,8 +326,9 @@ bool QWindowsFontEngineDirectWrite::stringToCMap(const QChar *str, int len, QGly
|
|||||||
|
|
||||||
QVarLengthArray<UINT32> codePoints(len);
|
QVarLengthArray<UINT32> codePoints(len);
|
||||||
int actualLength = 0;
|
int actualLength = 0;
|
||||||
for (int i = 0; i < len; ++i)
|
QStringIterator it(str, str + len);
|
||||||
codePoints[actualLength++] = getChar(str, i, len);
|
while (it.hasNext())
|
||||||
|
codePoints[actualLength++] = it.next();
|
||||||
|
|
||||||
QVarLengthArray<UINT16> glyphIndices(actualLength);
|
QVarLengthArray<UINT16> glyphIndices(actualLength);
|
||||||
HRESULT hr = m_directWriteFontFace->GetGlyphIndicesW(codePoints.data(), actualLength,
|
HRESULT hr = m_directWriteFontFace->GetGlyphIndicesW(codePoints.data(), actualLength,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user