summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/kernel/qkeysequence.cpp16
-rw-r--r--src/gui/painting/qpaintengine_raster.cpp4
-rw-r--r--src/gui/text/qfontengine.cpp3
-rw-r--r--src/gui/text/qfontengine_ft.cpp13
-rw-r--r--src/gui/text/qfontengine_qpa.cpp13
-rw-r--r--src/gui/text/qfontengine_qpf.cpp13
-rw-r--r--src/gui/text/qfontenginedirectwrite.cpp13
-rw-r--r--src/gui/text/qtextcursor.cpp4
-rw-r--r--src/gui/text/qtextengine.cpp3
-rw-r--r--src/gui/text/qtexthtmlparser.cpp12
10 files changed, 38 insertions, 56 deletions
diff --git a/src/gui/kernel/qkeysequence.cpp b/src/gui/kernel/qkeysequence.cpp
index 58ac03e92b..0c7af19d34 100644
--- a/src/gui/kernel/qkeysequence.cpp
+++ b/src/gui/kernel/qkeysequence.cpp
@@ -1380,11 +1380,11 @@ QString QKeySequencePrivate::encodeString(int key, QKeySequence::SequenceFormat
QString p;
if (key && key < Qt::Key_Escape && key != Qt::Key_Space) {
- if (key < 0x10000) {
- p = QChar(key & 0xffff).toUpper();
+ if (!QChar::requiresSurrogates(key)) {
+ p = QChar(ushort(key)).toUpper();
} else {
- p = QChar((key-0x10000)/0x400+0xd800);
- p += QChar((key-0x10000)%400+0xdc00);
+ p += QChar(QChar::highSurrogate(key));
+ p += QChar(QChar::lowSurrogate(key));
}
} else if (key >= Qt::Key_F1 && key <= Qt::Key_F35) {
p = nativeText ? QCoreApplication::translate("QShortcut", "F%1").arg(key - Qt::Key_F1 + 1)
@@ -1417,11 +1417,11 @@ NonSymbol:
// Or else characters like Qt::Key_aring may not get displayed
// (Really depends on you locale)
if (!keyname[i].name) {
- if (key < 0x10000) {
- p = QChar(key & 0xffff).toUpper();
+ if (!QChar::requiresSurrogates(key)) {
+ p = QChar(ushort(key)).toUpper();
} else {
- p = QChar((key-0x10000)/0x400+0xd800);
- p += QChar((key-0x10000)%400+0xdc00);
+ p += QChar(QChar::highSurrogate(key));
+ p += QChar(QChar::lowSurrogate(key));
}
}
}
diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp
index 566b4d5f61..4d4b88b229 100644
--- a/src/gui/painting/qpaintengine_raster.cpp
+++ b/src/gui/painting/qpaintengine_raster.cpp
@@ -3405,7 +3405,7 @@ void QRasterPaintEngine::drawBitmap(const QPointF &pos, const QImage &image, QSp
spans[n].y = y;
spans[n].coverage = 255;
int len = 1;
- while (src_x < w-1 && src[(src_x+1) >> 3] & (0x1 << ((src_x+1) & 7))) {
+ while (src_x+1 < w && src[(src_x+1) >> 3] & (0x1 << ((src_x+1) & 7))) {
++src_x;
++len;
}
@@ -3431,7 +3431,7 @@ void QRasterPaintEngine::drawBitmap(const QPointF &pos, const QImage &image, QSp
spans[n].y = y;
spans[n].coverage = 255;
int len = 1;
- while (src_x < w-1 && src[(src_x+1) >> 3] & (0x80 >> ((src_x+1) & 7))) {
+ while (src_x+1 < w && src[(src_x+1) >> 3] & (0x80 >> ((src_x+1) & 7))) {
++src_x;
++len;
}
diff --git a/src/gui/text/qfontengine.cpp b/src/gui/text/qfontengine.cpp
index a89bb18e94..f7f3b0e900 100644
--- a/src/gui/text/qfontengine.cpp
+++ b/src/gui/text/qfontengine.cpp
@@ -1344,8 +1344,7 @@ bool QFontEngineMulti::stringToCMap(const QChar *str, int len,
int glyph_pos = 0;
for (int i = 0; i < len; ++i) {
- bool surrogate = (str[i].unicode() >= 0xd800 && str[i].unicode() < 0xdc00 && i < len-1
- && str[i+1].unicode() >= 0xdc00 && str[i+1].unicode() < 0xe000);
+ bool surrogate = (str[i].isHighSurrogate() && i < len-1 && str[i+1].isLowSurrogate());
if (glyphs->glyphs[glyph_pos] == 0 && str[i].category() != QChar::Separator_Line) {
QGlyphLayoutInstance tmp = glyphs->instance(glyph_pos);
diff --git a/src/gui/text/qfontengine_ft.cpp b/src/gui/text/qfontengine_ft.cpp
index 25c7268a9c..0755d9d22f 100644
--- a/src/gui/text/qfontengine_ft.cpp
+++ b/src/gui/text/qfontengine_ft.cpp
@@ -1417,15 +1417,12 @@ void QFontEngineFT::getUnscaledGlyph(glyph_t glyph, QPainterPath *path, glyph_me
static inline unsigned int getChar(const QChar *str, int &i, const int len)
{
- unsigned int uc = str[i].unicode();
- if (uc >= 0xd800 && uc < 0xdc00 && i < len-1) {
- uint low = str[i+1].unicode();
- if (low >= 0xdc00 && low < 0xe000) {
- uc = (uc - 0xd800)*0x400 + (low - 0xdc00) + 0x10000;
- ++i;
- }
+ 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 uc;
+ return ucs4;
}
bool QFontEngineFT::canRender(const QChar *string, int len)
diff --git a/src/gui/text/qfontengine_qpa.cpp b/src/gui/text/qfontengine_qpa.cpp
index 6fd85150e3..7c09ae7cf8 100644
--- a/src/gui/text/qfontengine_qpa.cpp
+++ b/src/gui/text/qfontengine_qpa.cpp
@@ -225,15 +225,12 @@ QVariant QFontEngineQPA::extractHeaderField(const uchar *data, HeaderTag request
static inline unsigned int getChar(const QChar *str, int &i, const int len)
{
- unsigned int uc = str[i].unicode();
- if (uc >= 0xd800 && uc < 0xdc00 && i < len-1) {
- uint low = str[i+1].unicode();
- if (low >= 0xdc00 && low < 0xe000) {
- uc = (uc - 0xd800)*0x400 + (low - 0xdc00) + 0x10000;
- ++i;
- }
+ 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 uc;
+ return ucs4;
}
QFontEngineQPA::QFontEngineQPA(const QFontDef &def, const QByteArray &data)
diff --git a/src/gui/text/qfontengine_qpf.cpp b/src/gui/text/qfontengine_qpf.cpp
index 4c1045e2d5..584cdc0d66 100644
--- a/src/gui/text/qfontengine_qpf.cpp
+++ b/src/gui/text/qfontengine_qpf.cpp
@@ -278,15 +278,12 @@ QList<QByteArray> QFontEngineQPF::cleanUpAfterClientCrash(const QList<int> &cras
static inline unsigned int getChar(const QChar *str, int &i, const int len)
{
- unsigned int uc = str[i].unicode();
- if (uc >= 0xd800 && uc < 0xdc00 && i < len-1) {
- uint low = str[i+1].unicode();
- if (low >= 0xdc00 && low < 0xe000) {
- uc = (uc - 0xd800)*0x400 + (low - 0xdc00) + 0x10000;
- ++i;
- }
+ 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 uc;
+ return ucs4;
}
#ifdef QT_FONTS_ARE_RESOURCES
QFontEngineQPF::QFontEngineQPF(const QFontDef &def, const uchar *bytes, int size)
diff --git a/src/gui/text/qfontenginedirectwrite.cpp b/src/gui/text/qfontenginedirectwrite.cpp
index d6932738f5..5bac1172fa 100644
--- a/src/gui/text/qfontenginedirectwrite.cpp
+++ b/src/gui/text/qfontenginedirectwrite.cpp
@@ -269,15 +269,12 @@ QFixed QFontEngineDirectWrite::emSquareSize() const
inline unsigned int getChar(const QChar *str, int &i, const int len)
{
- unsigned int uc = str[i].unicode();
- if (uc >= 0xd800 && uc < 0xdc00 && i < len-1) {
- uint low = str[i+1].unicode();
- if (low >= 0xdc00 && low < 0xe000) {
- uc = (uc - 0xd800)*0x400 + (low - 0xdc00) + 0x10000;
- ++i;
- }
+ 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 uc;
+ return ucs4;
}
bool QFontEngineDirectWrite::stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs,
diff --git a/src/gui/text/qtextcursor.cpp b/src/gui/text/qtextcursor.cpp
index 8bbe86c4f3..2bebf4c861 100644
--- a/src/gui/text/qtextcursor.cpp
+++ b/src/gui/text/qtextcursor.cpp
@@ -1511,11 +1511,11 @@ void QTextCursor::deletePreviousChar()
const QTextFragmentData * const frag = fragIt.value();
int fpos = fragIt.position();
QChar uc = d->priv->buffer().at(d->anchor - fpos + frag->stringPosition);
- if (d->anchor > fpos && uc.unicode() >= 0xdc00 && uc.unicode() < 0xe000) {
+ if (d->anchor > fpos && uc.isLowSurrogate()) {
// second half of a surrogate, check if we have the first half as well,
// if yes delete both at once
uc = d->priv->buffer().at(d->anchor - 1 - fpos + frag->stringPosition);
- if (uc.unicode() >= 0xd800 && uc.unicode() < 0xdc00)
+ if (uc.isHighSurrogate())
--d->anchor;
}
diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp
index 91c96fce80..97d5a3baaf 100644
--- a/src/gui/text/qtextengine.cpp
+++ b/src/gui/text/qtextengine.cpp
@@ -993,8 +993,7 @@ static void heuristicSetGlyphAttributes(const QChar *uc, int length, QGlyphLayou
int glyph_pos = 0;
for (int i = 0; i < length; i++) {
- if (uc[i].unicode() >= 0xd800 && uc[i].unicode() < 0xdc00 && i < length-1
- && uc[i+1].unicode() >= 0xdc00 && uc[i+1].unicode() < 0xe000) {
+ if (uc[i].isHighSurrogate() && i < length-1 && uc[i+1].isLowSurrogate()) {
logClusters[i] = glyph_pos;
logClusters[++i] = glyph_pos;
} else {
diff --git a/src/gui/text/qtexthtmlparser.cpp b/src/gui/text/qtexthtmlparser.cpp
index 41dc1130ee..ced71f5c60 100644
--- a/src/gui/text/qtexthtmlparser.cpp
+++ b/src/gui/text/qtexthtmlparser.cpp
@@ -820,15 +820,11 @@ QString QTextHtmlParser::parseEntity()
if (uc >= 0x80 && uc < 0x80 + (sizeof(windowsLatin1ExtendedCharacters)/sizeof(windowsLatin1ExtendedCharacters[0])))
uc = windowsLatin1ExtendedCharacters[uc - 0x80];
QString str;
- if (uc > 0xffff) {
- // surrogate pair
- uc -= 0x10000;
- ushort high = uc/0x400 + 0xd800;
- ushort low = uc%0x400 + 0xdc00;
- str.append(QChar(high));
- str.append(QChar(low));
+ if (QChar::requiresSurrogates(uc)) {
+ str += QChar(QChar::highSurrogate(uc));
+ str += QChar(QChar::lowSurrogate(uc));
} else {
- str.append(QChar(uc));
+ str = QChar(uc);
}
return str;
}