src/gui/text/qfontdatabase_s60.cpp
changeset 25 e24348a560a6
parent 23 89e065397ea6
child 29 b72c6db6890b
equal deleted inserted replaced
23:89e065397ea6 25:e24348a560a6
    90     }
    90     }
    91     return result;
    91     return result;
    92 }
    92 }
    93 
    93 
    94 #if defined(QT_NO_FREETYPE)
    94 #if defined(QT_NO_FREETYPE)
    95 class QFontDatabaseS60StoreImplementation : public QFontDatabaseS60Store
    95 class QSymbianFontDatabaseExtrasImplementation : public QSymbianFontDatabaseExtras
    96 {
    96 {
    97 public:
    97 public:
    98     QFontDatabaseS60StoreImplementation();
    98     QSymbianFontDatabaseExtrasImplementation();
    99     ~QFontDatabaseS60StoreImplementation();
    99     ~QSymbianFontDatabaseExtrasImplementation();
   100 
   100 
   101     const QFontEngineS60Extensions *extension(const QString &typeface, bool bold, bool italic) const;
   101     const QSymbianTypeFaceExtras *extras(const QString &typeface, bool bold, bool italic) const;
   102 
   102 
   103 private:
   103 private:
   104     RHeap* m_heap;
   104     RHeap* m_heap;
   105     CFontStore *m_store;
   105     CFontStore *m_store;
   106     COpenFontRasterizer *m_rasterizer;
   106     COpenFontRasterizer *m_rasterizer;
   107     mutable QList<const QFontEngineS60Extensions *> m_extensions;
   107     mutable QList<const QSymbianTypeFaceExtras *> m_extras;
   108     mutable QHash<QString, const QFontEngineS60Extensions *> m_extensionsHash;
   108     mutable QHash<QString, const QSymbianTypeFaceExtras *> m_extrasHash;
   109 };
   109 };
   110 
   110 
   111 QFontDatabaseS60StoreImplementation::QFontDatabaseS60StoreImplementation()
   111 QSymbianFontDatabaseExtrasImplementation::QSymbianFontDatabaseExtrasImplementation()
   112 {
   112 {
   113     QStringList filters;
   113     QStringList filters;
   114     filters.append(QLatin1String("*.ttf"));
   114     filters.append(QLatin1String("*.ttf"));
   115     filters.append(QLatin1String("*.ccc"));
   115     filters.append(QLatin1String("*.ccc"));
   116     const QFileInfoList fontFiles = alternativeFilePaths(QLatin1String("resource\\Fonts"), filters);
   116     const QFileInfoList fontFiles = alternativeFilePaths(QLatin1String("resource\\Fonts"), filters);
   129         const QString fontFile = QDir::toNativeSeparators(fontFileInfo.absoluteFilePath());
   129         const QString fontFile = QDir::toNativeSeparators(fontFileInfo.absoluteFilePath());
   130         TPtrC fontFilePtr(qt_QString2TPtrC(fontFile));
   130         TPtrC fontFilePtr(qt_QString2TPtrC(fontFile));
   131         QT_TRAP_THROWING(m_store->AddFileL(fontFilePtr));
   131         QT_TRAP_THROWING(m_store->AddFileL(fontFilePtr));
   132     }
   132     }
   133 }
   133 }
   134 QFontDatabaseS60StoreImplementation::~QFontDatabaseS60StoreImplementation()
   134 
   135 {
   135 QSymbianFontDatabaseExtrasImplementation::~QSymbianFontDatabaseExtrasImplementation()
   136     typedef QList<const QFontEngineS60Extensions *>::iterator iterator;
   136 {
   137     for (iterator p = m_extensions.begin(); p != m_extensions.end(); ++p) {
   137     typedef QList<const QSymbianTypeFaceExtras *>::iterator iterator;
       
   138     for (iterator p = m_extras.begin(); p != m_extras.end(); ++p) {
   138         m_store->ReleaseFont((*p)->fontOwner());
   139         m_store->ReleaseFont((*p)->fontOwner());
   139         delete *p;
   140         delete *p;
   140     }
   141     }
   141 
   142 
   142     delete m_store;
   143     delete m_store;
   158             (COpenFont*)PtrAdd(aBitmapFont, valueIOpenFont & ~1) : // New behavior: iOpenFont is offset
   159             (COpenFont*)PtrAdd(aBitmapFont, valueIOpenFont & ~1) : // New behavior: iOpenFont is offset
   159             (COpenFont*)valueIOpenFont; // Old behavior: iOpenFont is pointer
   160             (COpenFont*)valueIOpenFont; // Old behavior: iOpenFont is pointer
   160 }
   161 }
   161 #endif // FNTSTORE_H_INLINES_SUPPORT_FMM
   162 #endif // FNTSTORE_H_INLINES_SUPPORT_FMM
   162 
   163 
   163 const QFontEngineS60Extensions *QFontDatabaseS60StoreImplementation::extension(const QString &typeface, 
   164 const QSymbianTypeFaceExtras *QSymbianFontDatabaseExtrasImplementation::extras(const QString &typeface,
   164                                                                                bool bold, bool italic) const
   165                                                                                bool bold, bool italic) const
   165 {
   166 {
   166     const QString searchKey = typeface + QString::number(int(bold)) + QString::number(int(italic));
   167     const QString searchKey = typeface + QString::number(int(bold)) + QString::number(int(italic));
   167     if (!m_extensionsHash.contains(searchKey)) {
   168     if (!m_extrasHash.contains(searchKey)) {
   168         CFont* font = NULL;
   169         CFont* font = NULL;
   169         TFontSpec searchSpec(qt_QString2TPtrC(typeface), 1);
   170         TFontSpec searchSpec(qt_QString2TPtrC(typeface), 1);
   170         if (bold)
   171         if (bold)
   171             searchSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
   172             searchSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
   172         if (italic)
   173         if (italic)
   181             OpenFontFromBitmapFont(bitmapFont);
   182             OpenFontFromBitmapFont(bitmapFont);
   182 #endif // FNTSTORE_H_INLINES_SUPPORT_FMM
   183 #endif // FNTSTORE_H_INLINES_SUPPORT_FMM
   183         const TOpenFontFaceAttrib* const attrib = openFont->FaceAttrib();
   184         const TOpenFontFaceAttrib* const attrib = openFont->FaceAttrib();
   184         const QString foundKey =
   185         const QString foundKey =
   185                 QString((const QChar*)attrib->FullName().Ptr(), attrib->FullName().Length());
   186                 QString((const QChar*)attrib->FullName().Ptr(), attrib->FullName().Length());
   186         if (!m_extensionsHash.contains(foundKey)) {
   187         if (!m_extrasHash.contains(foundKey)) {
   187             QFontEngineS60Extensions *extras = new QFontEngineS60Extensions(font, openFont);
   188             QSymbianTypeFaceExtras *extras = new QSymbianTypeFaceExtras(font, openFont);
   188             m_extensions.append(extras);
   189             m_extras.append(extras);
   189             m_extensionsHash.insert(searchKey, extras);
   190             m_extrasHash.insert(searchKey, extras);
   190             m_extensionsHash.insert(foundKey, extras);
   191             m_extrasHash.insert(foundKey, extras);
   191         } else {
   192         } else {
   192             m_store->ReleaseFont(font);
   193             m_store->ReleaseFont(font);
   193             m_extensionsHash.insert(searchKey, m_extensionsHash.value(foundKey));
   194             m_extrasHash.insert(searchKey, m_extrasHash.value(foundKey));
   194         }
   195         }
   195     }
   196     }
   196     return m_extensionsHash.value(searchKey);
   197     return m_extrasHash.value(searchKey);
   197 }
   198 }
   198 #else
   199 #else
   199 class QFontEngineFTS60 : public QFontEngineFT
   200 class QFontEngineFTS60 : public QFontEngineFT
   200 {
   201 {
   201 public:
   202 public:
   258     QFontDatabasePrivate *db = privateDb();
   259     QFontDatabasePrivate *db = privateDb();
   259     if(!db || db->count)
   260     if(!db || db->count)
   260         return;
   261         return;
   261 
   262 
   262 #if defined(QT_NO_FREETYPE)
   263 #if defined(QT_NO_FREETYPE)
   263     if (!db->s60Store)
   264     if (!db->symbianExtras)
   264         db->s60Store = new QFontDatabaseS60StoreImplementation;
   265         db->symbianExtras = new QSymbianFontDatabaseExtrasImplementation;
   265 
   266 
   266     QSymbianFbsHeapLock lock(QSymbianFbsHeapLock::Unlock);
   267     QSymbianFbsHeapLock lock(QSymbianFbsHeapLock::Unlock);
   267     
   268     
   268     const int numTypeFaces = QS60Data::screenDevice()->NumTypefaces();
   269     const int numTypeFaces = QS60Data::screenDevice()->NumTypefaces();
   269     const QFontDatabaseS60StoreImplementation *store =
   270     const QSymbianFontDatabaseExtrasImplementation *dbExtras =
   270             static_cast<const QFontDatabaseS60StoreImplementation*>(db->s60Store);
   271             static_cast<const QSymbianFontDatabaseExtrasImplementation*>(db->symbianExtras);
   271     bool fontAdded = false;
   272     bool fontAdded = false;
   272     for (int i = 0; i < numTypeFaces; i++) {
   273     for (int i = 0; i < numTypeFaces; i++) {
   273         TTypefaceSupport typefaceSupport;
   274         TTypefaceSupport typefaceSupport;
   274         QS60Data::screenDevice()->TypefaceSupport(typefaceSupport, i);
   275         QS60Data::screenDevice()->TypefaceSupport(typefaceSupport, i);
   275         CFont *font; // We have to get a font instance in order to know all the details
   276         CFont *font; // We have to get a font instance in order to know all the details
   291             QtFontFoundry *foundry = family->foundry(QString(), true);
   292             QtFontFoundry *foundry = family->foundry(QString(), true);
   292             QtFontStyle *style = foundry->style(styleKey, true);
   293             QtFontStyle *style = foundry->style(styleKey, true);
   293             style->smoothScalable = typefaceSupport.iIsScalable;
   294             style->smoothScalable = typefaceSupport.iIsScalable;
   294             style->pixelSize(0, true);
   295             style->pixelSize(0, true);
   295 
   296 
   296             const QFontEngineS60Extensions *extension = store->extension(familyName, faceAttrib.IsBold(), faceAttrib.IsItalic());
   297             const QSymbianTypeFaceExtras *typeFaceExtras =
   297             const QByteArray os2Table = extension->getSfntTable(MAKE_TAG('O', 'S', '/', '2'));
   298                     dbExtras->extras(familyName, faceAttrib.IsBold(), faceAttrib.IsItalic());
       
   299             const QByteArray os2Table = typeFaceExtras->getSfntTable(MAKE_TAG('O', 'S', '/', '2'));
   298             const unsigned char* data = reinterpret_cast<const unsigned char*>(os2Table.constData());
   300             const unsigned char* data = reinterpret_cast<const unsigned char*>(os2Table.constData());
   299             const unsigned char* ulUnicodeRange = data + 42;
   301             const unsigned char* ulUnicodeRange = data + 42;
   300             quint32 unicodeRange[4] = {
   302             quint32 unicodeRange[4] = {
   301                 qFromBigEndian<quint32>(ulUnicodeRange),
   303                 qFromBigEndian<quint32>(ulUnicodeRange),
   302                 qFromBigEndian<quint32>(ulUnicodeRange + 4),
   304                 qFromBigEndian<quint32>(ulUnicodeRange + 4),
   412 
   414 
   413         const QString fontFamily = desc.family->name;
   415         const QString fontFamily = desc.family->name;
   414         QFontDef request = req;
   416         QFontDef request = req;
   415         request.family = fontFamily;
   417         request.family = fontFamily;
   416 #if defined(QT_NO_FREETYPE)
   418 #if defined(QT_NO_FREETYPE)
   417         const QFontDatabaseS60StoreImplementation *store =
   419         const QSymbianFontDatabaseExtrasImplementation *dbExtras =
   418                 static_cast<const QFontDatabaseS60StoreImplementation*>(db->s60Store);
   420                 static_cast<const QSymbianFontDatabaseExtrasImplementation*>(db->symbianExtras);
   419         const QFontEngineS60Extensions *extension = store->extension(fontFamily, request.weight > QFont::Normal, request.style != QFont::StyleNormal );
   421         const QSymbianTypeFaceExtras *typeFaceExtras =
   420         fe = new QFontEngineS60(request, extension);
   422                 dbExtras->extras(fontFamily, request.weight > QFont::Normal, request.style != QFont::StyleNormal);
       
   423         fe = new QFontEngineS60(request, typeFaceExtras);
   421 #else
   424 #else
   422         QFontEngine::FaceId faceId;
   425         QFontEngine::FaceId faceId;
   423         const QtFontFamily * const reqQtFontFamily = db->family(fontFamily);
   426         const QtFontFamily * const reqQtFontFamily = db->family(fontFamily);
   424         faceId.filename = reqQtFontFamily->fontFilename;
   427         faceId.filename = reqQtFontFamily->fontFilename;
   425         faceId.index = reqQtFontFamily->fontFileIndex;
   428         faceId.index = reqQtFontFamily->fontFileIndex;