From 0c49838016ab77d596f53774d8432f9f4d6b1188 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Wed, 8 Sep 2010 21:01:21 +0200 Subject: Pulled some code from One long function into a short one Preparations for Application font support on Symbian Task-Number: QTBUG-6611 --- src/gui/text/qfontdatabase_s60.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/gui/text/qfontdatabase_s60.cpp b/src/gui/text/qfontdatabase_s60.cpp index 0b38aab..f9d8d31 100644 --- a/src/gui/text/qfontdatabase_s60.cpp +++ b/src/gui/text/qfontdatabase_s60.cpp @@ -99,6 +99,7 @@ public: ~QSymbianFontDatabaseExtrasImplementation(); const QSymbianTypeFaceExtras *extras(const QString &typeface, bool bold, bool italic) const; + void addFontFileToFontStore(const QFileInfo &fontFileInfo); #ifndef Q_SYMBIAN_HAS_FONTTABLE_API struct CFontFromFontStoreReleaser { @@ -150,11 +151,8 @@ QSymbianFontDatabaseExtrasImplementation::QSymbianFontDatabaseExtrasImplementati m_store->InstallRasterizerL(m_rasterizer); CleanupStack::Pop(m_rasterizer);); - foreach (const QFileInfo &fontFileInfo, fontFiles) { - const QString fontFile = QDir::toNativeSeparators(fontFileInfo.absoluteFilePath()); - TPtrC fontFilePtr(qt_QString2TPtrC(fontFile)); - QT_TRAP_THROWING(m_store->AddFileL(fontFilePtr)); - } + foreach (const QFileInfo &fontFileInfo, fontFiles) + addFontFileToFontStore(fontFileInfo); #endif // !Q_SYMBIAN_HAS_FONTTABLE_API } @@ -250,6 +248,14 @@ const QSymbianTypeFaceExtras *QSymbianFontDatabaseExtrasImplementation::extras(c } return m_extrasHash.value(searchKey); } + +void QSymbianFontDatabaseExtrasImplementation::addFontFileToFontStore(const QFileInfo &fontFileInfo) +{ + const QString fontFile = QDir::toNativeSeparators(fontFileInfo.absoluteFilePath()); + TPtrC fontFilePtr(qt_QString2TPtrC(fontFile)); + QT_TRAP_THROWING(m_store->AddFileL(fontFilePtr)); +} + #else // QT_NO_FREETYPE class QFontEngineFTS60 : public QFontEngineFT { -- cgit v0.12 From c207a85d9d8e541a30f7dd7f0721f204757650e1 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Wed, 8 Sep 2010 21:03:05 +0200 Subject: Moved font list getter to qfontdatabase_s60.cpp. Reusable. Preparations for Application font support on Symbian Task-Number: QTBUG-6611 --- src/gui/text/qfont_s60.cpp | 13 ++++--------- src/gui/text/qfontdatabase_s60.cpp | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/gui/text/qfont_s60.cpp b/src/gui/text/qfont_s60.cpp index 2d547a9..d39f30a 100644 --- a/src/gui/text/qfont_s60.cpp +++ b/src/gui/text/qfont_s60.cpp @@ -49,16 +49,11 @@ QT_BEGIN_NAMESPACE #ifdef QT_NO_FREETYPE Q_GLOBAL_STATIC(QMutex, lastResortFamilyMutex); +extern QStringList qt_symbian_fontFamiliesOnFontServer(); // qfontdatabase_s60.cpp Q_GLOBAL_STATIC_WITH_INITIALIZER(QStringList, fontFamiliesOnFontServer, { - QSymbianFbsHeapLock lock(QSymbianFbsHeapLock::Unlock); - const int numTypeFaces = S60->screenDevice()->NumTypefaces(); - for (int i = 0; i < numTypeFaces; i++) { - TTypefaceSupport typefaceSupport; - S60->screenDevice()->TypefaceSupport(typefaceSupport, i); - const QString familyName((const QChar *)typefaceSupport.iTypeface.iName.Ptr(), typefaceSupport.iTypeface.iName.Length()); - x->append(familyName); - } - lock.relock(); + // We are only interested in the initial font families. No Application fonts. + // Therefore, we are allowed to cache the list. + x->append(qt_symbian_fontFamiliesOnFontServer()); }); #endif // QT_NO_FREETYPE diff --git a/src/gui/text/qfontdatabase_s60.cpp b/src/gui/text/qfontdatabase_s60.cpp index f9d8d31..b73555f 100644 --- a/src/gui/text/qfontdatabase_s60.cpp +++ b/src/gui/text/qfontdatabase_s60.cpp @@ -58,6 +58,21 @@ QT_BEGIN_NAMESPACE +QStringList qt_symbian_fontFamiliesOnFontServer() // Also used in qfont_s60.cpp +{ + QStringList result; + QSymbianFbsHeapLock lock(QSymbianFbsHeapLock::Unlock); + const int numTypeFaces = S60->screenDevice()->NumTypefaces(); + for (int i = 0; i < numTypeFaces; i++) { + TTypefaceSupport typefaceSupport; + S60->screenDevice()->TypefaceSupport(typefaceSupport, i); + const QString familyName((const QChar *)typefaceSupport.iTypeface.iName.Ptr(), typefaceSupport.iTypeface.iName.Length()); + result.append(familyName); + } + lock.relock(); + return result; +} + QFileInfoList alternativeFilePaths(const QString &path, const QStringList &nameFilters, QDir::Filters filters = QDir::NoFilter, QDir::SortFlags sort = QDir::NoSort, bool uniqueFileNames = true) -- cgit v0.12 From 3c42576f2ef0cd9a2b55f33991f1fa8b168e5c03 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Wed, 8 Sep 2010 21:05:41 +0200 Subject: Pulled code form initializeDb() out into addFontToScreenDevice() Preparations for Application font support on Symbian Task-Number: QTBUG-6611 --- src/gui/text/qfontdatabase_s60.cpp | 105 +++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 52 deletions(-) diff --git a/src/gui/text/qfontdatabase_s60.cpp b/src/gui/text/qfontdatabase_s60.cpp index b73555f..ec252cd 100644 --- a/src/gui/text/qfontdatabase_s60.cpp +++ b/src/gui/text/qfontdatabase_s60.cpp @@ -331,6 +331,57 @@ void QFontEngineMultiS60::loadEngine(int at) Q_ASSERT(engines[at]); } +static bool addFontToScreenDevice(int screenDeviceFontIndex, + const QSymbianFontDatabaseExtrasImplementation *dbExtras) +{ + TTypefaceSupport typefaceSupport; + S60->screenDevice()->TypefaceSupport(typefaceSupport, screenDeviceFontIndex); + CFont *font; // We have to get a font instance in order to know all the details + TFontSpec fontSpec(typefaceSupport.iTypeface.iName, 11); + if (S60->screenDevice()->GetNearestFontInPixels(font, fontSpec) != KErrNone) + return false; + QScopedPointer sFont(font); + if (font->TypeUid() != KCFbsFontUid) + return false; + TOpenFontFaceAttrib faceAttrib; + const CFbsFont *cfbsFont = static_cast(font); + cfbsFont->GetFaceAttrib(faceAttrib); + + QtFontStyle::Key styleKey; + styleKey.style = faceAttrib.IsItalic()?QFont::StyleItalic:QFont::StyleNormal; + styleKey.weight = faceAttrib.IsBold()?QFont::Bold:QFont::Normal; + + QString familyName((const QChar *)typefaceSupport.iTypeface.iName.Ptr(), typefaceSupport.iTypeface.iName.Length()); + QtFontFamily *family = privateDb()->family(familyName, true); + family->fixedPitch = faceAttrib.IsMonoWidth(); + QtFontFoundry *foundry = family->foundry(QString(), true); + QtFontStyle *style = foundry->style(styleKey, true); + style->smoothScalable = typefaceSupport.iIsScalable; + style->pixelSize(0, true); + + const QSymbianTypeFaceExtras *typeFaceExtras = + dbExtras->extras(familyName, faceAttrib.IsBold(), faceAttrib.IsItalic()); + const QByteArray os2Table = typeFaceExtras->getSfntTable(MAKE_TAG('O', 'S', '/', '2')); + const unsigned char* data = reinterpret_cast(os2Table.constData()); + const unsigned char* ulUnicodeRange = data + 42; + quint32 unicodeRange[4] = { + qFromBigEndian(ulUnicodeRange), + qFromBigEndian(ulUnicodeRange + 4), + qFromBigEndian(ulUnicodeRange + 8), + qFromBigEndian(ulUnicodeRange + 12) + }; + const unsigned char* ulCodePageRange = data + 78; + quint32 codePageRange[2] = { + qFromBigEndian(ulCodePageRange), + qFromBigEndian(ulCodePageRange + 4) + }; + const QList writingSystems = + determineWritingSystemsFromTrueTypeBits(unicodeRange, codePageRange); + foreach (const QFontDatabase::WritingSystem system, writingSystems) + family->writingSystems[system] = QtFontFamily::Supported; + return true; +} + static void initializeDb() { QFontDatabasePrivate *db = privateDb(); @@ -346,59 +397,9 @@ static void initializeDb() const int numTypeFaces = S60->screenDevice()->NumTypefaces(); const QSymbianFontDatabaseExtrasImplementation *dbExtras = static_cast(db->symbianExtras); - bool fontAdded = false; - for (int i = 0; i < numTypeFaces; i++) { - TTypefaceSupport typefaceSupport; - S60->screenDevice()->TypefaceSupport(typefaceSupport, i); - CFont *font; // We have to get a font instance in order to know all the details - TFontSpec fontSpec(typefaceSupport.iTypeface.iName, 11); - if (S60->screenDevice()->GetNearestFontInPixels(font, fontSpec) != KErrNone) - continue; - QScopedPointer sFont(font); - if (font->TypeUid() == KCFbsFontUid) { - TOpenFontFaceAttrib faceAttrib; - const CFbsFont *cfbsFont = static_cast(font); - cfbsFont->GetFaceAttrib(faceAttrib); - - QtFontStyle::Key styleKey; - styleKey.style = faceAttrib.IsItalic()?QFont::StyleItalic:QFont::StyleNormal; - styleKey.weight = faceAttrib.IsBold()?QFont::Bold:QFont::Normal; - - QString familyName((const QChar *)typefaceSupport.iTypeface.iName.Ptr(), typefaceSupport.iTypeface.iName.Length()); - QtFontFamily *family = db->family(familyName, true); - family->fixedPitch = faceAttrib.IsMonoWidth(); - QtFontFoundry *foundry = family->foundry(QString(), true); - QtFontStyle *style = foundry->style(styleKey, true); - style->smoothScalable = typefaceSupport.iIsScalable; - style->pixelSize(0, true); - - const QSymbianTypeFaceExtras *typeFaceExtras = - dbExtras->extras(familyName, faceAttrib.IsBold(), faceAttrib.IsItalic()); - const QByteArray os2Table = typeFaceExtras->getSfntTable(MAKE_TAG('O', 'S', '/', '2')); - const unsigned char* data = reinterpret_cast(os2Table.constData()); - const unsigned char* ulUnicodeRange = data + 42; - quint32 unicodeRange[4] = { - qFromBigEndian(ulUnicodeRange), - qFromBigEndian(ulUnicodeRange + 4), - qFromBigEndian(ulUnicodeRange + 8), - qFromBigEndian(ulUnicodeRange + 12) - }; - const unsigned char* ulCodePageRange = data + 78; - quint32 codePageRange[2] = { - qFromBigEndian(ulCodePageRange), - qFromBigEndian(ulCodePageRange + 4) - }; - const QList writingSystems = - determineWritingSystemsFromTrueTypeBits(unicodeRange, codePageRange); - foreach (const QFontDatabase::WritingSystem system, writingSystems) - family->writingSystems[system] = QtFontFamily::Supported; - - fontAdded = true; - } - } + for (int i = 0; i < numTypeFaces; i++) + addFontToScreenDevice(i, dbExtras); - Q_ASSERT(fontAdded); - lock.relock(); #else // QT_NO_FREETYPE -- cgit v0.12