diff options
author | Konstantin Ritt <ritt.ks@gmail.com> | 2013-03-07 15:21:07 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-03-12 16:01:35 +0100 |
commit | 06a65b053e9b8697c0140219fdc3c28495426e77 (patch) | |
tree | fd25622333e5645d6c6762ad7595bcb514694696 /src/gui/text/qplatformfontdatabase.cpp | |
parent | 3cd94fcaf81ca5285c481c59b6ed4a720241820e (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/text/qplatformfontdatabase.cpp')
-rw-r--r-- | src/gui/text/qplatformfontdatabase.cpp | 101 |
1 files changed, 101 insertions, 0 deletions
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 |