summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qchar.cpp18
-rw-r--r--src/corelib/tools/qline.cpp21
-rw-r--r--src/corelib/tools/qstring.cpp2
3 files changed, 27 insertions, 14 deletions
diff --git a/src/corelib/tools/qchar.cpp b/src/corelib/tools/qchar.cpp
index 9db7d1a..b296129 100644
--- a/src/corelib/tools/qchar.cpp
+++ b/src/corelib/tools/qchar.cpp
@@ -1481,7 +1481,8 @@ static void decomposeHelper(QString *str, bool canonical, QChar::UnicodeVersion
ucs4 = QChar::surrogateToUcs4(high, ucs4);
}
}
- if (QChar::unicodeVersion(ucs4) > version)
+ QChar::UnicodeVersion v = QChar::unicodeVersion(ucs4);
+ if (v == QChar::Unicode_Unassigned || v > version)
continue;
int length;
int tag;
@@ -1541,7 +1542,7 @@ static ushort ligatureHelper(ushort u1, ushort u2)
return 0;
}
-static void composeHelper(QString *str, int from)
+static void composeHelper(QString *str, QChar::UnicodeVersion version, int from)
{
QString &s = *str;
@@ -1561,7 +1562,14 @@ static void composeHelper(QString *str, int from)
++pos;
}
}
- int combining = QChar::combiningClass(uc);
+ const QUnicodeTables::Properties *p = qGetProp(uc);
+ if (p->unicodeVersion == QChar::Unicode_Unassigned || p->unicodeVersion > version) {
+ starter = -1; // to prevent starter == pos - 1
+ lastCombining = 0;
+ ++pos;
+ continue;
+ }
+ int combining = p->combiningClass;
if (starter == pos - 1 || combining > lastCombining) {
// allowed to form ligature with S
QChar ligature = ligatureHelper(s.at(starter).unicode(), uc);
@@ -1608,7 +1616,7 @@ static void canonicalOrderHelper(QString *str, QChar::UnicodeVersion version, in
ushort c2 = 0;
{
const QUnicodeTables::Properties *p = qGetProp(u2);
- if ((QChar::UnicodeVersion)p->unicodeVersion <= version)
+ if (p->unicodeVersion != QChar::Unicode_Unassigned && p->unicodeVersion <= version)
c2 = p->combiningClass;
}
if (c2 == 0) {
@@ -1619,7 +1627,7 @@ static void canonicalOrderHelper(QString *str, QChar::UnicodeVersion version, in
ushort c1 = 0;
{
const QUnicodeTables::Properties *p = qGetProp(u1);
- if ((QChar::UnicodeVersion)p->unicodeVersion <= version)
+ if (p->unicodeVersion != QChar::Unicode_Unassigned && p->unicodeVersion <= version)
c1 = p->combiningClass;
}
diff --git a/src/corelib/tools/qline.cpp b/src/corelib/tools/qline.cpp
index 0f67652..9c7c243 100644
--- a/src/corelib/tools/qline.cpp
+++ b/src/corelib/tools/qline.cpp
@@ -302,10 +302,15 @@ QDataStream &operator>>(QDataStream &stream, QLine &line)
#endif // QT_NO_DATASTREAM
+inline static qreal q_deg2rad(qreal x)
+{
+ return x * qreal(0.01745329251994329576923690768489); /* pi/180 */
+}
-#ifndef M_2PI
-#define M_2PI 6.28318530717958647692528676655900576
-#endif
+inline static qreal q_rad2deg(qreal x)
+{
+ return x * qreal(57.295779513082320876798154814105); /* 180/pi */
+}
/*!
\class QLineF
@@ -575,7 +580,7 @@ qreal QLineF::angle() const
const qreal dx = pt2.x() - pt1.x();
const qreal dy = pt2.y() - pt1.y();
- const qreal theta = qAtan2(-dy, dx) * 360.0 / M_2PI;
+ const qreal theta = q_rad2deg(qAtan2(-dy, dx));
const qreal theta_normalized = theta < 0 ? theta + 360 : theta;
@@ -599,7 +604,7 @@ qreal QLineF::angle() const
*/
void QLineF::setAngle(qreal angle)
{
- const qreal angleR = angle * M_2PI / 360.0;
+ const qreal angleR = q_deg2rad(angle);
const qreal l = length();
const qreal dx = qCos(angleR) * l;
@@ -621,7 +626,7 @@ void QLineF::setAngle(qreal angle)
*/
QLineF QLineF::fromPolar(qreal length, qreal angle)
{
- const qreal angleR = angle * M_2PI / 360.0;
+ const qreal angleR = q_deg2rad(angle);
return QLineF(0, 0, qCos(angleR) * length, -qSin(angleR) * length);
}
@@ -815,8 +820,8 @@ qreal QLineF::angle(const QLineF &l) const
qreal cos_line = (dx()*l.dx() + dy()*l.dy()) / (length()*l.length());
qreal rad = 0;
// only accept cos_line in the range [-1,1], if it is outside, use 0 (we return 0 rather than PI for those cases)
- if (cos_line >= -1.0 && cos_line <= 1.0) rad = qAcos( cos_line );
- return rad * 360 / M_2PI;
+ if (cos_line >= qreal(-1.0) && cos_line <= qreal(1.0)) rad = qAcos( cos_line );
+ return q_rad2deg(rad);
}
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index f5efe55..934b6ad 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/tools/qstring.cpp
@@ -6367,7 +6367,7 @@ void qt_string_normalize(QString *data, QString::NormalizationForm mode, QChar::
if (mode == QString::NormalizationForm_D || mode == QString::NormalizationForm_KD)
return;
- composeHelper(data, from);
+ composeHelper(data, version, from);
}