1
1
/****************************************************************************
3
3
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4
** All rights reserved.
4
5
** Contact: Nokia Corporation (qt-info@nokia.com)
6
7
** This file is part of the QtGui module of the Qt Toolkit.
8
9
** $QT_BEGIN_LICENSE:LGPL$
10
** Licensees holding valid Qt Commercial licenses may use this file in
11
** accordance with the Qt Commercial License Agreement provided with the
12
** Software or, alternatively, in accordance with the terms contained in
13
** a written agreement between you and Nokia.
10
** No Commercial Usage
11
** This file contains pre-release code and may not be distributed.
12
** You may use this file in accordance with the terms and conditions
13
** contained in the Technology Preview License Agreement accompanying
15
16
** GNU Lesser General Public License Usage
16
17
** Alternatively, this file may be used under the terms of the GNU Lesser
20
21
** ensure the GNU Lesser General Public License version 2.1 requirements
21
22
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23
** In addition, as a special exception, Nokia gives you certain
24
** additional rights. These rights are described in the Nokia Qt LGPL
25
** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
28
** GNU General Public License Usage
29
** Alternatively, this file may be used under the terms of the GNU
30
** General Public License version 3.0 as published by the Free Software
31
** Foundation and appearing in the file LICENSE.GPL included in the
32
** packaging of this file. Please review the following information to
33
** ensure the GNU General Public License version 3.0 requirements will be
34
** met: http://www.gnu.org/copyleft/gpl.html.
36
** If you are unsure which license is appropriate for your use, please
37
** contact the sales department at http://www.qtsoftware.com/contact.
24
** In addition, as a special exception, Nokia gives you certain additional
25
** rights. These rights are described in the Nokia Qt LGPL Exception
26
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28
** If you have questions regarding the use of this file, please contact
29
** Nokia at qt-info@nokia.com.
38
38
** $QT_END_LICENSE$
40
40
****************************************************************************/
87
99
// Test in decreasing order of commonness
88
100
if (s == QLatin1String("medium") ||
89
101
s == QLatin1String("normal")
90
|| s.compare(qApp->translate("QFontDatabase", "Normal"), Qt::CaseInsensitive) == 0)
102
|| s.compare(QApplication::translate("QFontDatabase", "Normal"), Qt::CaseInsensitive) == 0)
91
103
return QFont::Normal;
92
104
if (s == QLatin1String("bold")
93
|| s.compare(qApp->translate("QFontDatabase", "Bold"), Qt::CaseInsensitive) == 0)
105
|| s.compare(QApplication::translate("QFontDatabase", "Bold"), Qt::CaseInsensitive) == 0)
94
106
return QFont::Bold;
95
107
if (s == QLatin1String("demibold") || s == QLatin1String("demi bold")
96
|| s.compare(qApp->translate("QFontDatabase", "Demi Bold"), Qt::CaseInsensitive) == 0)
108
|| s.compare(QApplication::translate("QFontDatabase", "Demi Bold"), Qt::CaseInsensitive) == 0)
97
109
return QFont::DemiBold;
98
110
if (s == QLatin1String("black")
99
|| s.compare(qApp->translate("QFontDatabase", "Black"), Qt::CaseInsensitive) == 0)
111
|| s.compare(QApplication::translate("QFontDatabase", "Black"), Qt::CaseInsensitive) == 0)
100
112
return QFont::Black;
101
113
if (s == QLatin1String("light"))
102
114
return QFont::Light;
104
116
if (s.contains(QLatin1String("bold"))
105
|| s.contains(qApp->translate("QFontDatabase", "Bold"), Qt::CaseInsensitive)) {
117
|| s.contains(QApplication::translate("QFontDatabase", "Bold"), Qt::CaseInsensitive)) {
106
118
if (s.contains(QLatin1String("demi"))
107
|| s.compare(qApp->translate("QFontDatabase", "Demi"), Qt::CaseInsensitive) == 0)
119
|| s.compare(QApplication::translate("QFontDatabase", "Demi"), Qt::CaseInsensitive) == 0)
108
120
return (int) QFont::DemiBold;
109
121
return (int) QFont::Bold;
112
124
if (s.contains(QLatin1String("light"))
113
|| s.compare(qApp->translate("QFontDatabase", "Light"), Qt::CaseInsensitive) == 0)
125
|| s.compare(QApplication::translate("QFontDatabase", "Light"), Qt::CaseInsensitive) == 0)
114
126
return (int) QFont::Light;
116
128
if (s.contains(QLatin1String("black"))
117
|| s.compare(qApp->translate("QFontDatabase", "Black"), Qt::CaseInsensitive) == 0)
129
|| s.compare(QApplication::translate("QFontDatabase", "Black"), Qt::CaseInsensitive) == 0)
118
130
return (int) QFont::Black;
120
132
return (int) QFont::Normal;
610
655
#if defined(Q_WS_QWS)
611
656
bool loadFromCache(const QString &fontPath);
657
void addQPF2File(const QByteArray &file);
659
#if defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN) && !defined(QT_NO_FREETYPE)
612
660
void addFont(const QString &familyname, const char *foundryname, int weight,
613
661
bool italic, int pixelSize, const QByteArray &file, int fileIndex,
614
662
bool antialiased,
615
663
const QList<QFontDatabase::WritingSystem> &writingSystems = QList<QFontDatabase::WritingSystem>());
616
void addQPF2File(const QByteArray &file);
617
664
#ifndef QT_NO_FREETYPE
618
665
QStringList addTTFile(const QByteArray &file, const QByteArray &fontData = QByteArray());
666
#endif // QT_NO_FREETYPE
668
#if defined(Q_WS_QWS)
621
669
QDataStream *stream;
622
670
QStringList fallbackFamilies;
671
#elif defined(Q_OS_SYMBIAN) && defined(QT_NO_FREETYPE)
672
const QFontDatabaseS60Store *s60Store;
656
706
// qDebug("adding family %s at %d total=%d", f.latin1(), pos, count);
658
families = (QtFontFamily **)
708
QtFontFamily **newFamilies = (QtFontFamily **)
659
709
realloc(families,
660
710
(((count+8) >> 3) << 3) * sizeof(QtFontFamily *));
711
Q_CHECK_PTR(newFamilies);
712
families = newFamilies;
715
QtFontFamily *family = new QtFontFamily(f);
662
716
memmove(families + pos + 1, families + pos, (count-pos)*sizeof(QtFontFamily *));
663
families[pos] = new QtFontFamily(f);
717
families[pos] = family;
665
719
return families[pos];
722
#if defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN) && !defined(QT_NO_FREETYPE)
723
void QFontDatabasePrivate::addFont(const QString &familyname, const char *foundryname, int weight, bool italic, int pixelSize,
724
const QByteArray &file, int fileIndex, bool antialiased,
725
const QList<QFontDatabase::WritingSystem> &writingSystems)
727
// qDebug() << "Adding font" << familyname << weight << italic << pixelSize << file << fileIndex << antialiased;
728
QtFontStyle::Key styleKey;
729
styleKey.style = italic ? QFont::StyleItalic : QFont::StyleNormal;
730
styleKey.weight = weight;
731
styleKey.stretch = 100;
732
QtFontFamily *f = family(familyname, true);
734
if (writingSystems.isEmpty()) {
735
for (int ws = 1; ws < QFontDatabase::WritingSystemsCount; ++ws) {
736
f->writingSystems[ws] = QtFontFamily::Supported;
738
f->bogusWritingSystems = true;
740
for (int i = 0; i < writingSystems.count(); ++i) {
741
f->writingSystems[writingSystems.at(i)] = QtFontFamily::Supported;
745
QtFontFoundry *foundry = f->foundry(QString::fromLatin1(foundryname), true);
746
QtFontStyle *style = foundry->style(styleKey, true);
747
style->smoothScalable = (pixelSize == 0);
748
style->antialiased = antialiased;
749
QtFontSize *size = style->pixelSize(pixelSize?pixelSize:SMOOTH_SCALABLE, true);
750
size->fileName = file;
751
size->fileIndex = fileIndex;
753
#if defined(Q_WS_QWS)
755
*stream << familyname << foundry->name << weight << quint8(italic) << pixelSize
756
<< file << fileIndex << quint8(antialiased);
757
*stream << quint8(writingSystems.count());
758
for (int i = 0; i < writingSystems.count(); ++i)
759
*stream << quint8(writingSystems.at(i));
761
#else // ..in case of defined(Q_OS_SYMBIAN) && !defined(QT_NO_FREETYPE)
762
f->fontFilename = file;
763
f->fontFileIndex = fileIndex;
768
#if (defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN)) && !defined(QT_NO_FREETYPE)
769
QStringList QFontDatabasePrivate::addTTFile(const QByteArray &file, const QByteArray &fontData)
771
QStringList families;
772
extern FT_Library qt_getFreetype();
773
FT_Library library = qt_getFreetype();
780
if (!fontData.isEmpty()) {
781
error = FT_New_Memory_Face(library, (const FT_Byte *)fontData.constData(), fontData.size(), index, &face);
783
error = FT_New_Face(library, file, index, &face);
785
if (error != FT_Err_Ok) {
786
qDebug() << "FT_New_Face failed with index" << index << ":" << hex << error;
789
numFaces = face->num_faces;
791
int weight = QFont::Normal;
792
bool italic = face->style_flags & FT_STYLE_FLAG_ITALIC;
794
if (face->style_flags & FT_STYLE_FLAG_BOLD)
795
weight = QFont::Bold;
797
QList<QFontDatabase::WritingSystem> writingSystems;
798
// detect symbol fonts
799
for (int i = 0; i < face->num_charmaps; ++i) {
800
FT_CharMap cm = face->charmaps[i];
801
if (cm->encoding == ft_encoding_adobe_custom
802
|| cm->encoding == ft_encoding_symbol) {
803
writingSystems.append(QFontDatabase::Symbol);
807
if (writingSystems.isEmpty()) {
808
TT_OS2 *os2 = (TT_OS2 *)FT_Get_Sfnt_Table(face, ft_sfnt_os2);
810
quint32 unicodeRange[4] = {
811
os2->ulUnicodeRange1, os2->ulUnicodeRange2, os2->ulUnicodeRange3, os2->ulUnicodeRange4
813
quint32 codePageRange[2] = {
814
os2->ulCodePageRange1, os2->ulCodePageRange2
817
writingSystems = determineWritingSystemsFromTrueTypeBits(unicodeRange, codePageRange);
818
//for (int i = 0; i < writingSystems.count(); ++i)
819
// qDebug() << QFontDatabase::writingSystemName(writingSystems.at(i));
823
QString family = QString::fromAscii(face->family_name);
824
families.append(family);
825
addFont(family, /*foundry*/ "", weight, italic,
826
/*pixelsize*/ 0, file, index, /*antialias*/ true, writingSystems);
830
} while (index < numFaces);
669
835
static const int scriptForWritingSystem[] = {
670
836
QUnicodeTables::Common, // Any
1250
1416
QString result;
1251
1417
if (weight >= QFont::Black)
1252
result = qApp->translate("QFontDatabase", "Black");
1418
result = QApplication::translate("QFontDatabase", "Black");
1253
1419
else if (weight >= QFont::Bold)
1254
result = qApp->translate("QFontDatabase", "Bold");
1420
result = QApplication::translate("QFontDatabase", "Bold");
1255
1421
else if (weight >= QFont::DemiBold)
1256
result = qApp->translate("QFontDatabase", "Demi Bold");
1422
result = QApplication::translate("QFontDatabase", "Demi Bold");
1257
1423
else if (weight < QFont::Normal)
1258
result = qApp->translate("QFontDatabase", "Light");
1424
result = QApplication::translate("QFontDatabase", "Light");
1260
1426
if (style == QFont::StyleItalic)
1261
result += QLatin1Char(' ') + qApp->translate("QFontDatabase", "Italic");
1427
result += QLatin1Char(' ') + QApplication::translate("QFontDatabase", "Italic");
1262
1428
else if (style == QFont::StyleOblique)
1263
result += QLatin1Char(' ') + qApp->translate("QFontDatabase", "Oblique");
1429
result += QLatin1Char(' ') + QApplication::translate("QFontDatabase", "Oblique");
1265
1431
if (result.isEmpty())
1266
result = qApp->translate("QFontDatabase", "Normal");
1432
result = QApplication::translate("QFontDatabase", "Normal");
1268
1434
return result.simplified();