author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Thu, 27 May 2010 13:40:48 +0300 | |
changeset 23 | 89e065397ea6 |
parent 19 | fcece45ef507 |
child 25 | e24348a560a6 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7 |
** This file is part of the QtGui module of the Qt Toolkit. |
0 | 8 |
** |
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
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 |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
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. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include <private/qapplication_p.h> |
|
43 |
#include "qdir.h" |
|
44 |
#include "qfont_p.h" |
|
45 |
#include "qfontengine_s60_p.h" |
|
46 |
#include "qabstractfileengine.h" |
|
47 |
#include "qdesktopservices.h" |
|
48 |
#include "qpixmap_s60_p.h" |
|
49 |
#include "qt_s60_p.h" |
|
50 |
#include "qendian.h" |
|
51 |
#include <private/qcore_symbian_p.h> |
|
52 |
#if defined(QT_NO_FREETYPE) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
53 |
#include <openfont.h> |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
54 |
#ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
55 |
#include <graphics/openfontrasterizer.h> // COpenFontRasterizer has moved to a new header file |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
56 |
#endif // SYMBIAN_ENABLE_SPLIT_HEADERS |
0 | 57 |
#endif |
58 |
||
59 |
QT_BEGIN_NAMESPACE |
|
60 |
||
61 |
QFileInfoList alternativeFilePaths(const QString &path, const QStringList &nameFilters, |
|
62 |
QDir::Filters filters = QDir::NoFilter, QDir::SortFlags sort = QDir::NoSort, |
|
63 |
bool uniqueFileNames = true) |
|
64 |
{ |
|
65 |
QFileInfoList result; |
|
66 |
||
67 |
// Prepare a 'soft to hard' drive list: W:, X: ... A:, Z: |
|
68 |
QStringList driveStrings; |
|
69 |
foreach (const QFileInfo &drive, QDir::drives()) |
|
70 |
driveStrings.append(drive.absolutePath()); |
|
71 |
driveStrings.sort(); |
|
72 |
const QString zDriveString(QLatin1String("Z:/")); |
|
73 |
driveStrings.removeAll(zDriveString); |
|
74 |
driveStrings.prepend(zDriveString); |
|
75 |
||
76 |
QStringList uniqueFileNameList; |
|
77 |
for (int i = driveStrings.count() - 1; i >= 0; --i) { |
|
78 |
const QDir dirOnDrive(driveStrings.at(i) + path); |
|
79 |
const QFileInfoList entriesOnDrive = dirOnDrive.entryInfoList(nameFilters, filters, sort); |
|
80 |
if (uniqueFileNames) { |
|
81 |
foreach(const QFileInfo &entry, entriesOnDrive) { |
|
82 |
if (!uniqueFileNameList.contains(entry.fileName())) { |
|
83 |
uniqueFileNameList.append(entry.fileName()); |
|
84 |
result.append(entry); |
|
85 |
} |
|
86 |
} |
|
87 |
} else { |
|
88 |
result.append(entriesOnDrive); |
|
89 |
} |
|
90 |
} |
|
91 |
return result; |
|
92 |
} |
|
93 |
||
94 |
#if defined(QT_NO_FREETYPE) |
|
95 |
class QFontDatabaseS60StoreImplementation : public QFontDatabaseS60Store |
|
96 |
{ |
|
97 |
public: |
|
98 |
QFontDatabaseS60StoreImplementation(); |
|
99 |
~QFontDatabaseS60StoreImplementation(); |
|
100 |
||
23
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
101 |
const QFontEngineS60Extensions *extension(const QString &typeface, bool bold, bool italic) const; |
0 | 102 |
|
103 |
private: |
|
104 |
RHeap* m_heap; |
|
105 |
CFontStore *m_store; |
|
106 |
COpenFontRasterizer *m_rasterizer; |
|
23
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
107 |
mutable QList<const QFontEngineS60Extensions *> m_extensions; |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
108 |
mutable QHash<QString, const QFontEngineS60Extensions *> m_extensionsHash; |
0 | 109 |
}; |
110 |
||
111 |
QFontDatabaseS60StoreImplementation::QFontDatabaseS60StoreImplementation() |
|
112 |
{ |
|
23
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
113 |
QStringList filters; |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
114 |
filters.append(QLatin1String("*.ttf")); |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
115 |
filters.append(QLatin1String("*.ccc")); |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
116 |
const QFileInfoList fontFiles = alternativeFilePaths(QLatin1String("resource\\Fonts"), filters); |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
117 |
|
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
118 |
const TInt heapMinLength = 0x1000; |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
119 |
const TInt heapMaxLength = qMax(0x20000 * fontFiles.count(), heapMinLength); |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
120 |
m_heap = User::ChunkHeap(NULL, heapMinLength, heapMaxLength); |
0 | 121 |
QT_TRAP_THROWING( |
122 |
m_store = CFontStore::NewL(m_heap); |
|
123 |
m_rasterizer = COpenFontRasterizer::NewL(TUid::Uid(0x101F7F5E)); |
|
124 |
CleanupStack::PushL(m_rasterizer); |
|
125 |
m_store->InstallRasterizerL(m_rasterizer); |
|
126 |
CleanupStack::Pop(m_rasterizer);); |
|
127 |
||
128 |
foreach (const QFileInfo &fontFileInfo, fontFiles) { |
|
129 |
const QString fontFile = QDir::toNativeSeparators(fontFileInfo.absoluteFilePath()); |
|
130 |
TPtrC fontFilePtr(qt_QString2TPtrC(fontFile)); |
|
131 |
QT_TRAP_THROWING(m_store->AddFileL(fontFilePtr)); |
|
132 |
} |
|
133 |
} |
|
134 |
QFontDatabaseS60StoreImplementation::~QFontDatabaseS60StoreImplementation() |
|
135 |
{ |
|
23
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
136 |
typedef QList<const QFontEngineS60Extensions *>::iterator iterator; |
0 | 137 |
for (iterator p = m_extensions.begin(); p != m_extensions.end(); ++p) { |
138 |
m_store->ReleaseFont((*p)->fontOwner()); |
|
139 |
delete *p; |
|
140 |
} |
|
141 |
||
142 |
delete m_store; |
|
143 |
m_heap->Close(); |
|
144 |
} |
|
145 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
146 |
#ifndef FNTSTORE_H_INLINES_SUPPORT_FMM |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
147 |
/* |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
148 |
Workaround: fntstore.h has an inlined function 'COpenFont* CBitmapFont::OpenFont()' |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
149 |
that returns a private data member. The header will change between SDKs. But Qt has |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
150 |
to build on any SDK version and run on other versions of Symbian OS. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
151 |
This function performs the needed pointer arithmetic to get the right COpenFont* |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
152 |
*/ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
153 |
COpenFont* OpenFontFromBitmapFont(const CBitmapFont* aBitmapFont) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
154 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
155 |
const TInt offsetIOpenFont = 92; // '_FOFF(CBitmapFont, iOpenFont)' ..if iOpenFont weren't private |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
156 |
const TUint valueIOpenFont = *(TUint*)PtrAdd(aBitmapFont, offsetIOpenFont); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
157 |
return (valueIOpenFont & 1) ? |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
158 |
(COpenFont*)PtrAdd(aBitmapFont, valueIOpenFont & ~1) : // New behavior: iOpenFont is offset |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
159 |
(COpenFont*)valueIOpenFont; // Old behavior: iOpenFont is pointer |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
160 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
161 |
#endif // FNTSTORE_H_INLINES_SUPPORT_FMM |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
162 |
|
23
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
163 |
const QFontEngineS60Extensions *QFontDatabaseS60StoreImplementation::extension(const QString &typeface, |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
164 |
bool bold, bool italic) const |
0 | 165 |
{ |
23
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
166 |
const QString searchKey = typeface + QString::number(int(bold)) + QString::number(int(italic)); |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
167 |
if (!m_extensionsHash.contains(searchKey)) { |
0 | 168 |
CFont* font = NULL; |
23
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
169 |
TFontSpec searchSpec(qt_QString2TPtrC(typeface), 1); |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
170 |
if (bold) |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
171 |
searchSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold); |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
172 |
if (italic) |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
173 |
searchSpec.iFontStyle.SetPosture(EPostureItalic); |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
174 |
const TInt err = m_store->GetNearestFontToDesignHeightInPixels(font, searchSpec); |
0 | 175 |
Q_ASSERT(err == KErrNone && font); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
176 |
const CBitmapFont *bitmapFont = static_cast<CBitmapFont*>(font); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
177 |
COpenFont *openFont = |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
178 |
#ifdef FNTSTORE_H_INLINES_SUPPORT_FMM |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
179 |
bitmapFont->openFont(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
180 |
#else |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
181 |
OpenFontFromBitmapFont(bitmapFont); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
182 |
#endif // FNTSTORE_H_INLINES_SUPPORT_FMM |
23
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
183 |
const TOpenFontFaceAttrib* const attrib = openFont->FaceAttrib(); |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
184 |
const QString foundKey = |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
185 |
QString((const QChar*)attrib->FullName().Ptr(), attrib->FullName().Length()); |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
186 |
if (!m_extensionsHash.contains(foundKey)) { |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
187 |
QFontEngineS60Extensions *extras = new QFontEngineS60Extensions(font, openFont); |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
188 |
m_extensions.append(extras); |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
189 |
m_extensionsHash.insert(searchKey, extras); |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
190 |
m_extensionsHash.insert(foundKey, extras); |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
191 |
} else { |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
192 |
m_store->ReleaseFont(font); |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
193 |
m_extensionsHash.insert(searchKey, m_extensionsHash.value(foundKey)); |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
194 |
} |
0 | 195 |
} |
23
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
196 |
return m_extensionsHash.value(searchKey); |
0 | 197 |
} |
198 |
#else |
|
199 |
class QFontEngineFTS60 : public QFontEngineFT |
|
200 |
{ |
|
201 |
public: |
|
202 |
QFontEngineFTS60(const QFontDef &fd); |
|
203 |
}; |
|
204 |
||
205 |
QFontEngineFTS60::QFontEngineFTS60(const QFontDef &fd) |
|
206 |
: QFontEngineFT(fd) |
|
207 |
{ |
|
208 |
default_hint_style = HintFull; |
|
209 |
} |
|
210 |
#endif // defined(QT_NO_FREETYPE) |
|
211 |
||
212 |
/* |
|
213 |
QFontEngineS60::pixelsToPoints, QFontEngineS60::pointsToPixels, QFontEngineMultiS60::QFontEngineMultiS60 |
|
214 |
and QFontEngineMultiS60::QFontEngineMultiS60 should be in qfontengine_s60.cpp. But since also the |
|
215 |
Freetype based font rendering need them, they are here. |
|
216 |
*/ |
|
217 |
qreal QFontEngineS60::pixelsToPoints(qreal pixels, Qt::Orientation orientation) |
|
218 |
{ |
|
219 |
return (orientation == Qt::Horizontal? |
|
220 |
S60->screenDevice()->HorizontalPixelsToTwips(pixels) |
|
221 |
:S60->screenDevice()->VerticalPixelsToTwips(pixels)) / KTwipsPerPoint; |
|
222 |
} |
|
223 |
||
224 |
qreal QFontEngineS60::pointsToPixels(qreal points, Qt::Orientation orientation) |
|
225 |
{ |
|
226 |
const int twips = points * KTwipsPerPoint; |
|
227 |
return orientation == Qt::Horizontal? |
|
228 |
S60->screenDevice()->HorizontalTwipsToPixels(twips) |
|
229 |
:S60->screenDevice()->VerticalTwipsToPixels(twips); |
|
230 |
} |
|
231 |
||
232 |
QFontEngineMultiS60::QFontEngineMultiS60(QFontEngine *first, int script, const QStringList &fallbackFamilies) |
|
233 |
: QFontEngineMulti(fallbackFamilies.size() + 1) |
|
234 |
, m_script(script) |
|
235 |
, m_fallbackFamilies(fallbackFamilies) |
|
236 |
{ |
|
237 |
engines[0] = first; |
|
238 |
first->ref.ref(); |
|
239 |
fontDef = engines[0]->fontDef; |
|
240 |
} |
|
241 |
||
242 |
void QFontEngineMultiS60::loadEngine(int at) |
|
243 |
{ |
|
244 |
Q_ASSERT(at < engines.size()); |
|
245 |
Q_ASSERT(engines.at(at) == 0); |
|
246 |
||
247 |
QFontDef request = fontDef; |
|
248 |
request.styleStrategy |= QFont::NoFontMerging; |
|
249 |
request.family = m_fallbackFamilies.at(at-1); |
|
250 |
engines[at] = QFontDatabase::findFont(m_script, |
|
251 |
/*fontprivate*/0, |
|
252 |
request); |
|
253 |
Q_ASSERT(engines[at]); |
|
254 |
} |
|
255 |
||
256 |
static void initializeDb() |
|
257 |
{ |
|
258 |
QFontDatabasePrivate *db = privateDb(); |
|
259 |
if(!db || db->count) |
|
260 |
return; |
|
261 |
||
262 |
#if defined(QT_NO_FREETYPE) |
|
263 |
if (!db->s60Store) |
|
264 |
db->s60Store = new QFontDatabaseS60StoreImplementation; |
|
265 |
||
266 |
QSymbianFbsHeapLock lock(QSymbianFbsHeapLock::Unlock); |
|
267 |
||
268 |
const int numTypeFaces = QS60Data::screenDevice()->NumTypefaces(); |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
269 |
const QFontDatabaseS60StoreImplementation *store = |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
270 |
static_cast<const QFontDatabaseS60StoreImplementation*>(db->s60Store); |
0 | 271 |
bool fontAdded = false; |
272 |
for (int i = 0; i < numTypeFaces; i++) { |
|
273 |
TTypefaceSupport typefaceSupport; |
|
274 |
QS60Data::screenDevice()->TypefaceSupport(typefaceSupport, i); |
|
275 |
CFont *font; // We have to get a font instance in order to know all the details |
|
276 |
TFontSpec fontSpec(typefaceSupport.iTypeface.iName, 11); |
|
277 |
if (QS60Data::screenDevice()->GetNearestFontInPixels(font, fontSpec) != KErrNone) |
|
278 |
continue; |
|
279 |
if (font->TypeUid() == KCFbsFontUid) { |
|
280 |
TOpenFontFaceAttrib faceAttrib; |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
281 |
const CFbsFont *cfbsFont = static_cast<const CFbsFont *>(font); |
0 | 282 |
cfbsFont->GetFaceAttrib(faceAttrib); |
283 |
||
284 |
QtFontStyle::Key styleKey; |
|
285 |
styleKey.style = faceAttrib.IsItalic()?QFont::StyleItalic:QFont::StyleNormal; |
|
286 |
styleKey.weight = faceAttrib.IsBold()?QFont::Bold:QFont::Normal; |
|
287 |
||
288 |
QString familyName((const QChar *)typefaceSupport.iTypeface.iName.Ptr(), typefaceSupport.iTypeface.iName.Length()); |
|
289 |
QtFontFamily *family = db->family(familyName, true); |
|
290 |
family->fixedPitch = faceAttrib.IsMonoWidth(); |
|
291 |
QtFontFoundry *foundry = family->foundry(QString(), true); |
|
292 |
QtFontStyle *style = foundry->style(styleKey, true); |
|
293 |
style->smoothScalable = typefaceSupport.iIsScalable; |
|
294 |
style->pixelSize(0, true); |
|
295 |
||
23
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
296 |
const QFontEngineS60Extensions *extension = store->extension(familyName, faceAttrib.IsBold(), faceAttrib.IsItalic()); |
0 | 297 |
const QByteArray os2Table = extension->getSfntTable(MAKE_TAG('O', 'S', '/', '2')); |
298 |
const unsigned char* data = reinterpret_cast<const unsigned char*>(os2Table.constData()); |
|
299 |
const unsigned char* ulUnicodeRange = data + 42; |
|
300 |
quint32 unicodeRange[4] = { |
|
301 |
qFromBigEndian<quint32>(ulUnicodeRange), |
|
302 |
qFromBigEndian<quint32>(ulUnicodeRange + 4), |
|
303 |
qFromBigEndian<quint32>(ulUnicodeRange + 8), |
|
304 |
qFromBigEndian<quint32>(ulUnicodeRange + 12) |
|
305 |
}; |
|
306 |
const unsigned char* ulCodePageRange = data + 78; |
|
307 |
quint32 codePageRange[2] = { |
|
308 |
qFromBigEndian<quint32>(ulCodePageRange), |
|
309 |
qFromBigEndian<quint32>(ulCodePageRange + 4) |
|
310 |
}; |
|
311 |
const QList<QFontDatabase::WritingSystem> writingSystems = |
|
312 |
determineWritingSystemsFromTrueTypeBits(unicodeRange, codePageRange); |
|
313 |
foreach (const QFontDatabase::WritingSystem system, writingSystems) |
|
314 |
family->writingSystems[system] = QtFontFamily::Supported; |
|
315 |
||
316 |
fontAdded = true; |
|
317 |
} |
|
318 |
QS60Data::screenDevice()->ReleaseFont(font); |
|
319 |
} |
|
320 |
||
321 |
Q_ASSERT(fontAdded); |
|
322 |
||
323 |
lock.relock(); |
|
324 |
||
325 |
#else // defined(QT_NO_FREETYPE) |
|
326 |
QDir dir(QDesktopServices::storageLocation(QDesktopServices::FontsLocation)); |
|
327 |
dir.setNameFilters(QStringList() << QLatin1String("*.ttf") |
|
328 |
<< QLatin1String("*.ttc") << QLatin1String("*.pfa") |
|
329 |
<< QLatin1String("*.pfb")); |
|
330 |
for (int i = 0; i < int(dir.count()); ++i) { |
|
331 |
const QByteArray file = QFile::encodeName(dir.absoluteFilePath(dir[i])); |
|
332 |
db->addTTFile(file); |
|
333 |
} |
|
334 |
#endif // defined(QT_NO_FREETYPE) |
|
335 |
} |
|
336 |
||
337 |
static inline void load(const QString &family = QString(), int script = -1) |
|
338 |
{ |
|
339 |
Q_UNUSED(family) |
|
340 |
Q_UNUSED(script) |
|
341 |
initializeDb(); |
|
342 |
} |
|
343 |
||
344 |
static void registerFont(QFontDatabasePrivate::ApplicationFont *fnt) |
|
345 |
{ |
|
346 |
Q_UNUSED(fnt); |
|
347 |
} |
|
348 |
||
349 |
bool QFontDatabase::removeApplicationFont(int handle) |
|
350 |
{ |
|
351 |
Q_UNUSED(handle); |
|
352 |
return false; |
|
353 |
} |
|
354 |
||
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
355 |
bool QFontDatabase::removeAllApplicationFonts() |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
356 |
{ |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
357 |
return false; |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
358 |
} |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
359 |
|
0 | 360 |
bool QFontDatabase::supportsThreadedFontRendering() |
361 |
{ |
|
362 |
return false; |
|
363 |
} |
|
364 |
||
365 |
static |
|
366 |
QFontDef cleanedFontDef(const QFontDef &req) |
|
367 |
{ |
|
368 |
QFontDef result = req; |
|
369 |
if (result.pixelSize <= 0) { |
|
370 |
result.pixelSize = QFontEngineS60::pointsToPixels(qMax(qreal(1.0), result.pointSize)); |
|
371 |
result.pointSize = 0; |
|
372 |
} |
|
373 |
return result; |
|
374 |
} |
|
375 |
||
376 |
QFontEngine *QFontDatabase::findFont(int script, const QFontPrivate *, const QFontDef &req) |
|
377 |
{ |
|
378 |
const QFontCache::Key key(cleanedFontDef(req), script); |
|
379 |
||
380 |
if (!privateDb()->count) |
|
381 |
initializeDb(); |
|
382 |
||
383 |
QFontEngine *fe = QFontCache::instance()->findEngine(key); |
|
384 |
if (!fe) { |
|
385 |
// Making sure that fe->fontDef.family will be an existing font. |
|
386 |
initializeDb(); |
|
387 |
QFontDatabasePrivate *db = privateDb(); |
|
388 |
QtFontDesc desc; |
|
389 |
QList<int> blacklistedFamilies; |
|
390 |
match(script, req, req.family, QString(), -1, &desc, blacklistedFamilies); |
|
391 |
if (!desc.family) // falling back to application font |
|
392 |
desc.family = db->family(QApplication::font().defaultFamily()); |
|
393 |
Q_ASSERT(desc.family); |
|
394 |
||
395 |
// Making sure that desc.family supports the requested script |
|
396 |
QtFontDesc mappedDesc; |
|
397 |
bool supportsScript = false; |
|
398 |
do { |
|
399 |
match(script, req, QString(), QString(), -1, &mappedDesc, blacklistedFamilies); |
|
400 |
if (mappedDesc.family == desc.family) { |
|
401 |
supportsScript = true; |
|
402 |
break; |
|
403 |
} |
|
404 |
blacklistedFamilies.append(mappedDesc.familyIndex); |
|
405 |
} while (mappedDesc.family); |
|
406 |
if (!supportsScript) { |
|
407 |
blacklistedFamilies.clear(); |
|
408 |
match(script, req, QString(), QString(), -1, &mappedDesc, blacklistedFamilies); |
|
409 |
if (mappedDesc.family) |
|
410 |
desc = mappedDesc; |
|
411 |
} |
|
412 |
||
413 |
const QString fontFamily = desc.family->name; |
|
414 |
QFontDef request = req; |
|
415 |
request.family = fontFamily; |
|
416 |
#if defined(QT_NO_FREETYPE) |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
417 |
const QFontDatabaseS60StoreImplementation *store = |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
418 |
static_cast<const QFontDatabaseS60StoreImplementation*>(db->s60Store); |
23
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
419 |
const QFontEngineS60Extensions *extension = store->extension(fontFamily, request.weight > QFont::Normal, request.style != QFont::StyleNormal ); |
0 | 420 |
fe = new QFontEngineS60(request, extension); |
421 |
#else |
|
422 |
QFontEngine::FaceId faceId; |
|
423 |
const QtFontFamily * const reqQtFontFamily = db->family(fontFamily); |
|
424 |
faceId.filename = reqQtFontFamily->fontFilename; |
|
425 |
faceId.index = reqQtFontFamily->fontFileIndex; |
|
426 |
||
427 |
QFontEngineFTS60 *fte = new QFontEngineFTS60(cleanedFontDef(request)); |
|
428 |
if (fte->init(faceId, true, QFontEngineFT::Format_A8)) |
|
429 |
fe = fte; |
|
430 |
else |
|
431 |
delete fte; |
|
432 |
#endif |
|
433 |
||
434 |
Q_ASSERT(fe); |
|
435 |
if (script == QUnicodeTables::Common |
|
436 |
&& !(req.styleStrategy & QFont::NoFontMerging) |
|
437 |
&& !fe->symbol) { |
|
438 |
||
439 |
QStringList commonFonts; |
|
440 |
for (int ws = 1; ws < QFontDatabase::WritingSystemsCount; ++ws) { |
|
441 |
if (scriptForWritingSystem[ws] != script) |
|
442 |
continue; |
|
443 |
for (int i = 0; i < db->count; ++i) { |
|
444 |
if (db->families[i]->writingSystems[ws] & QtFontFamily::Supported) |
|
445 |
commonFonts.append(db->families[i]->name); |
|
446 |
} |
|
447 |
} |
|
448 |
||
449 |
// Hack: Prioritize .ccc fonts |
|
450 |
const QString niceEastAsianFont(QLatin1String("Sans MT 936_S60")); |
|
451 |
if (commonFonts.removeAll(niceEastAsianFont) > 0) |
|
452 |
commonFonts.prepend(niceEastAsianFont); |
|
453 |
||
454 |
fe = new QFontEngineMultiS60(fe, script, commonFonts); |
|
455 |
} |
|
456 |
} |
|
457 |
fe->ref.ref(); |
|
458 |
QFontCache::instance()->insertEngine(key, fe); |
|
459 |
return fe; |
|
460 |
} |
|
461 |
||
462 |
void QFontDatabase::load(const QFontPrivate *d, int script) |
|
463 |
{ |
|
464 |
QFontEngine *fe = 0; |
|
465 |
QFontDef req = d->request; |
|
466 |
||
467 |
if (!d->engineData) { |
|
468 |
const QFontCache::Key key(cleanedFontDef(req), script); |
|
469 |
getEngineData(d, key); |
|
470 |
} |
|
471 |
||
472 |
// the cached engineData could have already loaded the engine we want |
|
473 |
if (d->engineData->engines[script]) |
|
474 |
fe = d->engineData->engines[script]; |
|
475 |
||
476 |
if (!fe) { |
|
477 |
if (qt_enable_test_font && req.family == QLatin1String("__Qt__Box__Engine__")) { |
|
478 |
fe = new QTestFontEngine(req.pixelSize); |
|
479 |
fe->fontDef = req; |
|
480 |
} else { |
|
481 |
fe = findFont(script, d, req); |
|
482 |
} |
|
483 |
d->engineData->engines[script] = fe; |
|
484 |
} |
|
485 |
} |
|
486 |
||
487 |
QT_END_NAMESPACE |