summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorKonstantin Ritt <ritt.ks@gmail.com>2013-03-07 15:21:07 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-03-12 16:01:35 +0100
commit06a65b053e9b8697c0140219fdc3c28495426e77 (patch)
treefd25622333e5645d6c6762ad7595bcb514694696 /src/gui
parent3cd94fcaf81ca5285c481c59b6ed4a720241820e (diff)
Get rid of qt_determine_writing_systems_from_truetype_bits()
Move this code to QPlatformFontDatabase and get rid of all dups of it. Change-Id: Idea6c84819039bf3b345b1305305951ade8d1ac4 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/text/qfontdatabase.cpp127
-rw-r--r--src/gui/text/qplatformfontdatabase.cpp101
-rw-r--r--src/gui/text/qplatformfontdatabase.h3
-rw-r--r--src/gui/text/qrawfont.cpp13
4 files changed, 112 insertions, 132 deletions
diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp
index f937e7a820..f052d8fd89 100644
--- a/src/gui/text/qfontdatabase.cpp
+++ b/src/gui/text/qfontdatabase.cpp
@@ -383,133 +383,6 @@ QtFontFoundry *QtFontFamily::foundry(const QString &f, bool create)
return foundries[count++];
}
-// ### copied to tools/makeqpf/qpf2.cpp
-
-// see the Unicode subset bitfields in the MSDN docs
-static int requiredUnicodeBits[QFontDatabase::WritingSystemsCount][2] = {
- // Any,
- { 127, 127 },
- // Latin,
- { 0, 127 },
- // Greek,
- { 7, 127 },
- // Cyrillic,
- { 9, 127 },
- // Armenian,
- { 10, 127 },
- // Hebrew,
- { 11, 127 },
- // Arabic,
- { 13, 127 },
- // Syriac,
- { 71, 127 },
- //Thaana,
- { 72, 127 },
- //Devanagari,
- { 15, 127 },
- //Bengali,
- { 16, 127 },
- //Gurmukhi,
- { 17, 127 },
- //Gujarati,
- { 18, 127 },
- //Oriya,
- { 19, 127 },
- //Tamil,
- { 20, 127 },
- //Telugu,
- { 21, 127 },
- //Kannada,
- { 22, 127 },
- //Malayalam,
- { 23, 127 },
- //Sinhala,
- { 73, 127 },
- //Thai,
- { 24, 127 },
- //Lao,
- { 25, 127 },
- //Tibetan,
- { 70, 127 },
- //Myanmar,
- { 74, 127 },
- // Georgian,
- { 26, 127 },
- // Khmer,
- { 80, 127 },
- // SimplifiedChinese,
- { 126, 127 },
- // TraditionalChinese,
- { 126, 127 },
- // Japanese,
- { 126, 127 },
- // Korean,
- { 56, 127 },
- // Vietnamese,
- { 0, 127 }, // same as latin1
- // Other,
- { 126, 127 },
- // Ogham,
- { 78, 127 },
- // Runic,
- { 79, 127 },
- // Nko,
- { 14, 127 },
-};
-
-#define SimplifiedChineseCsbBit 18
-#define TraditionalChineseCsbBit 20
-#define JapaneseCsbBit 17
-#define KoreanCsbBit 21
-
-QList<QFontDatabase::WritingSystem> qt_determine_writing_systems_from_truetype_bits(quint32 unicodeRange[4], quint32 codePageRange[2])
-{
- QList<QFontDatabase::WritingSystem> writingSystems;
- bool hasScript = false;
-
- int i;
- for(i = 0; i < QFontDatabase::WritingSystemsCount; i++) {
- int bit = requiredUnicodeBits[i][0];
- int index = bit/32;
- int flag = 1 << (bit&31);
- if (bit != 126 && unicodeRange[index] & flag) {
- bit = requiredUnicodeBits[i][1];
- index = bit/32;
-
- flag = 1 << (bit&31);
- if (bit == 127 || unicodeRange[index] & flag) {
- writingSystems.append(QFontDatabase::WritingSystem(i));
- hasScript = true;
- // qDebug("font %s: index=%d, flag=%8x supports script %d", familyName.latin1(), index, flag, i);
- }
- }
- }
- if(codePageRange[0] & (1 << SimplifiedChineseCsbBit)) {
- writingSystems.append(QFontDatabase::SimplifiedChinese);
- hasScript = true;
- //qDebug("font %s supports Simplified Chinese", familyName.latin1());
- }
- if(codePageRange[0] & (1 << TraditionalChineseCsbBit)) {
- writingSystems.append(QFontDatabase::TraditionalChinese);
- hasScript = true;
- //qDebug("font %s supports Traditional Chinese", familyName.latin1());
- }
- if(codePageRange[0] & (1 << JapaneseCsbBit)) {
- writingSystems.append(QFontDatabase::Japanese);
- hasScript = true;
- //qDebug("font %s supports Japanese", familyName.latin1());
- }
- if(codePageRange[0] & (1 << KoreanCsbBit)) {
- writingSystems.append(QFontDatabase::Korean);
- hasScript = true;
- //qDebug("font %s supports Korean", familyName.latin1());
- }
- if (!hasScript)
- writingSystems.append(QFontDatabase::Symbol);
-
- return writingSystems;
-}
-
class QFontDatabasePrivate
{
diff --git a/src/gui/text/qplatformfontdatabase.cpp b/src/gui/text/qplatformfontdatabase.cpp
index 08e697cacf..4e2a2df66a 100644
--- a/src/gui/text/qplatformfontdatabase.cpp
+++ b/src/gui/text/qplatformfontdatabase.cpp
@@ -413,6 +413,107 @@ bool QPlatformFontDatabase::fontsAlwaysScalable() const
return ret;
}
+
+// ### copied to tools/makeqpf/qpf2.cpp
+
+// see the Unicode subset bitfields in the MSDN docs
+static const ushort requiredUnicodeBits[QFontDatabase::WritingSystemsCount][2] = {
+ { 127, 127 }, // Any
+ { 0, 127 }, // Latin
+ { 7, 127 }, // Greek
+ { 9, 127 }, // Cyrillic
+ { 10, 127 }, // Armenian
+ { 11, 127 }, // Hebrew
+ { 13, 127 }, // Arabic
+ { 71, 127 }, // Syriac
+ { 72, 127 }, // Thaana
+ { 15, 127 }, // Devanagari
+ { 16, 127 }, // Bengali
+ { 17, 127 }, // Gurmukhi
+ { 18, 127 }, // Gujarati
+ { 19, 127 }, // Oriya
+ { 20, 127 }, // Tamil
+ { 21, 127 }, // Telugu
+ { 22, 127 }, // Kannada
+ { 23, 127 }, // Malayalam
+ { 73, 127 }, // Sinhala
+ { 24, 127 }, // Thai
+ { 25, 127 }, // Lao
+ { 70, 127 }, // Tibetan
+ { 74, 127 }, // Myanmar
+ { 26, 127 }, // Georgian
+ { 80, 127 }, // Khmer
+ { 126, 127 }, // SimplifiedChinese
+ { 126, 127 }, // TraditionalChinese
+ { 126, 127 }, // Japanese
+ { 56, 127 }, // Korean
+ { 0, 127 }, // Vietnamese (same as latin1)
+ { 126, 127 }, // Other
+ { 78, 127 }, // Ogham
+ { 79, 127 }, // Runic
+ { 14, 127 }, // Nko
+};
+
+enum {
+ SimplifiedChineseCsbBit = 18,
+ TraditionalChineseCsbBit = 20,
+ JapaneseCsbBit = 17,
+ KoreanCsbBit = 21
+};
+
+/*!
+ Helper function that determines the writing systems support by a given
+ \a unicodeRange and \a codePageRange.
+
+ \since 5.1
+*/
+QSupportedWritingSystems QPlatformFontDatabase::writingSystemsFromTrueTypeBits(quint32 unicodeRange[4], quint32 codePageRange[2])
+{
+ QSupportedWritingSystems writingSystems;
+
+ bool hasScript = false;
+ for (int i = 0; i < QFontDatabase::WritingSystemsCount; ++i) {
+ int bit = requiredUnicodeBits[i][0];
+ int index = bit/32;
+ int flag = 1 << (bit&31);
+ if (bit != 126 && (unicodeRange[index] & flag)) {
+ bit = requiredUnicodeBits[i][1];
+ index = bit/32;
+
+ flag = 1 << (bit&31);
+ if (bit == 127 || (unicodeRange[index] & flag)) {
+ writingSystems.setSupported(QFontDatabase::WritingSystem(i));
+ hasScript = true;
+ // qDebug("font %s: index=%d, flag=%8x supports script %d", familyName.latin1(), index, flag, i);
+ }
+ }
+ }
+ if (codePageRange[0] & (1 << SimplifiedChineseCsbBit)) {
+ writingSystems.setSupported(QFontDatabase::SimplifiedChinese);
+ hasScript = true;
+ //qDebug("font %s supports Simplified Chinese", familyName.latin1());
+ }
+ if (codePageRange[0] & (1 << TraditionalChineseCsbBit)) {
+ writingSystems.setSupported(QFontDatabase::TraditionalChinese);
+ hasScript = true;
+ //qDebug("font %s supports Traditional Chinese", familyName.latin1());
+ }
+ if (codePageRange[0] & (1 << JapaneseCsbBit)) {
+ writingSystems.setSupported(QFontDatabase::Japanese);
+ hasScript = true;
+ //qDebug("font %s supports Japanese", familyName.latin1());
+ }
+ if (codePageRange[0] & (1 << KoreanCsbBit)) {
+ writingSystems.setSupported(QFontDatabase::Korean);
+ hasScript = true;
+ //qDebug("font %s supports Korean", familyName.latin1());
+ }
+ if (!hasScript)
+ writingSystems.setSupported(QFontDatabase::Symbol);
+
+ return writingSystems;
+}
+
/*!
\class QPlatformFontDatabase
\since 5.0
diff --git a/src/gui/text/qplatformfontdatabase.h b/src/gui/text/qplatformfontdatabase.h
index 4b20677cbb..6e53eba98b 100644
--- a/src/gui/text/qplatformfontdatabase.h
+++ b/src/gui/text/qplatformfontdatabase.h
@@ -112,6 +112,9 @@ public:
virtual bool fontsAlwaysScalable() const;
virtual QList<int> standardSizes() const;
+ // helper
+ static QSupportedWritingSystems writingSystemsFromTrueTypeBits(quint32 unicodeRange[4], quint32 codePageRange[2]);
+
//callback
static void registerQPF2Font(const QByteArray &dataArray, void *handle);
static void registerFont(const QString &familyname, const QString &stylename,
diff --git a/src/gui/text/qrawfont.cpp b/src/gui/text/qrawfont.cpp
index 279f0ecd90..567586495c 100644
--- a/src/gui/text/qrawfont.cpp
+++ b/src/gui/text/qrawfont.cpp
@@ -45,6 +45,7 @@
#include "qrawfont.h"
#include "qrawfont_p.h"
+#include "qplatformfontdatabase.h"
#include <QtCore/qendian.h>
@@ -574,9 +575,6 @@ QByteArray QRawFont::fontTable(const char *tagName) const
return d->fontEngine->getSfntTable(qToBigEndian(*tagId));
}
-// From qfontdatabase.cpp
-extern QList<QFontDatabase::WritingSystem> qt_determine_writing_systems_from_truetype_bits(quint32 unicodeRange[4], quint32 codePageRange[2]);
-
/*!
Returns a list of writing systems supported by the font according to designer supplied
information in the font file. Please note that this does not guarantee support for a
@@ -590,6 +588,7 @@ extern QList<QFontDatabase::WritingSystem> qt_determine_writing_systems_from_tru
*/
QList<QFontDatabase::WritingSystem> QRawFont::supportedWritingSystems() const
{
+ QList<QFontDatabase::WritingSystem> writingSystems;
if (d->isValid()) {
QByteArray os2Table = fontTable("OS/2");
if (os2Table.size() > 86) {
@@ -606,11 +605,15 @@ QList<QFontDatabase::WritingSystem> QRawFont::supportedWritingSystems() const
unicodeRanges[i] = qFromBigEndian(bigEndianUnicodeRanges[i]);
}
- return qt_determine_writing_systems_from_truetype_bits(unicodeRanges, codepageRanges);
+ QSupportedWritingSystems ws = QPlatformFontDatabase::writingSystemsFromTrueTypeBits(unicodeRanges, codepageRanges);
+ for (int i = 0; i < QFontDatabase::WritingSystemsCount; ++i) {
+ if (ws.supported(QFontDatabase::WritingSystem(i)))
+ writingSystems.append(QFontDatabase::WritingSystem(i));
+ }
}
}
- return QList<QFontDatabase::WritingSystem>();
+ return writingSystems;
}
/*!