diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2010-05-10 08:42:47 (GMT) |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2010-05-10 08:42:47 (GMT) |
commit | 42d46a85a50926cd24d7216cb99b4084f6d8ad04 (patch) | |
tree | 39a79b4709f6da1c04c60a5c3e5adf43c16f6169 /src/gui/text | |
parent | 37b45fe0415bd6695640b26eb7545280b2e8ffe1 (diff) | |
parent | a863691765b1788a17a67e826f483b68f0f34066 (diff) | |
download | Qt-42d46a85a50926cd24d7216cb99b4084f6d8ad04.zip Qt-42d46a85a50926cd24d7216cb99b4084f6d8ad04.tar.gz Qt-42d46a85a50926cd24d7216cb99b4084f6d8ad04.tar.bz2 |
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/oslo-staging-2 into 4.7
Diffstat (limited to 'src/gui/text')
-rw-r--r-- | src/gui/text/qfont.cpp | 5 | ||||
-rw-r--r-- | src/gui/text/qfontdatabase.cpp | 14 | ||||
-rw-r--r-- | src/gui/text/qfontdatabase_s60.cpp | 85 | ||||
-rw-r--r-- | src/gui/text/qfontengine_s60.cpp | 55 | ||||
-rw-r--r-- | src/gui/text/qfontengine_s60_p.h | 12 | ||||
-rw-r--r-- | src/gui/text/qtextdocument.cpp | 9 |
6 files changed, 88 insertions, 92 deletions
diff --git a/src/gui/text/qfont.cpp b/src/gui/text/qfont.cpp index 24887b5..21a31a3 100644 --- a/src/gui/text/qfont.cpp +++ b/src/gui/text/qfont.cpp @@ -2616,10 +2616,8 @@ void QFontCache::cleanup() } QT_CATCH (const std::bad_alloc &) { // no cache - just ignore } - if (cache && cache->hasLocalData()) { - cache->localData()->clear(); + if (cache && cache->hasLocalData()) cache->setLocalData(0); - } } #endif // QT_NO_THREAD @@ -2631,6 +2629,7 @@ QFontCache::QFontCache() QFontCache::~QFontCache() { + clear(); { EngineDataCache::ConstIterator it = engineDataCache.constBegin(), end = engineDataCache.constEnd(); diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp index ae5e9ca..ff29462 100644 --- a/src/gui/text/qfontdatabase.cpp +++ b/src/gui/text/qfontdatabase.cpp @@ -598,10 +598,10 @@ static QList<QFontDatabase::WritingSystem> determineWritingSystemsFromTrueTypeBi #if defined(Q_OS_SYMBIAN) && defined(QT_NO_FREETYPE) // class with virtual destructor, derived in qfontdatabase_s60.cpp -class QFontDatabaseS60Store +class QSymbianFontDatabaseExtras { public: - virtual ~QFontDatabaseS60Store() {} + virtual ~QSymbianFontDatabaseExtras() {} }; #endif @@ -614,7 +614,7 @@ public: , stream(0) #endif #if defined(Q_OS_SYMBIAN) && defined(QT_NO_FREETYPE) - , s60Store(0) + , symbianExtras(0) #endif { } ~QFontDatabasePrivate() { @@ -628,9 +628,9 @@ public: families = 0; count = 0; #if defined(Q_OS_SYMBIAN) && defined(QT_NO_FREETYPE) - if (s60Store) { - delete s60Store; - s60Store = 0; + if (symbianExtras) { + delete symbianExtras; + symbianExtras = 0; } #endif // don't clear the memory fonts! @@ -675,7 +675,7 @@ public: QDataStream *stream; QStringList fallbackFamilies; #elif defined(Q_OS_SYMBIAN) && defined(QT_NO_FREETYPE) - const QFontDatabaseS60Store *s60Store; + const QSymbianFontDatabaseExtras *symbianExtras; #endif }; diff --git a/src/gui/text/qfontdatabase_s60.cpp b/src/gui/text/qfontdatabase_s60.cpp index ef5e0c4..95774f9 100644 --- a/src/gui/text/qfontdatabase_s60.cpp +++ b/src/gui/text/qfontdatabase_s60.cpp @@ -92,24 +92,32 @@ QFileInfoList alternativeFilePaths(const QString &path, const QStringList &nameF } #if defined(QT_NO_FREETYPE) -class QFontDatabaseS60StoreImplementation : public QFontDatabaseS60Store +class QSymbianFontDatabaseExtrasImplementation : public QSymbianFontDatabaseExtras { public: - QFontDatabaseS60StoreImplementation(); - ~QFontDatabaseS60StoreImplementation(); + QSymbianFontDatabaseExtrasImplementation(); + ~QSymbianFontDatabaseExtrasImplementation(); - const QFontEngineS60Extensions *extension(const QString &typeface) const; + const QSymbianTypeFaceExtras *extras(const QString &typeface, bool bold, bool italic) const; private: RHeap* m_heap; CFontStore *m_store; COpenFontRasterizer *m_rasterizer; - mutable QHash<QString, const QFontEngineS60Extensions *> m_extensions; + mutable QList<const QSymbianTypeFaceExtras *> m_extras; + mutable QHash<QString, const QSymbianTypeFaceExtras *> m_extrasHash; }; -QFontDatabaseS60StoreImplementation::QFontDatabaseS60StoreImplementation() +QSymbianFontDatabaseExtrasImplementation::QSymbianFontDatabaseExtrasImplementation() { - m_heap = User::ChunkHeap(NULL, 0x1000, 0x100000); + QStringList filters; + filters.append(QLatin1String("*.ttf")); + filters.append(QLatin1String("*.ccc")); + const QFileInfoList fontFiles = alternativeFilePaths(QLatin1String("resource\\Fonts"), filters); + + const TInt heapMinLength = 0x1000; + const TInt heapMaxLength = qMax(0x20000 * fontFiles.count(), heapMinLength); + m_heap = User::ChunkHeap(NULL, heapMinLength, heapMaxLength); QT_TRAP_THROWING( m_store = CFontStore::NewL(m_heap); m_rasterizer = COpenFontRasterizer::NewL(TUid::Uid(0x101F7F5E)); @@ -117,20 +125,17 @@ QFontDatabaseS60StoreImplementation::QFontDatabaseS60StoreImplementation() m_store->InstallRasterizerL(m_rasterizer); CleanupStack::Pop(m_rasterizer);); - QStringList filters; - filters.append(QString::fromLatin1("*.ttf")); - filters.append(QString::fromLatin1("*.ccc")); - const QFileInfoList fontFiles = alternativeFilePaths(QString::fromLatin1("resource\\Fonts"), filters); foreach (const QFileInfo &fontFileInfo, fontFiles) { const QString fontFile = QDir::toNativeSeparators(fontFileInfo.absoluteFilePath()); TPtrC fontFilePtr(qt_QString2TPtrC(fontFile)); QT_TRAP_THROWING(m_store->AddFileL(fontFilePtr)); } } -QFontDatabaseS60StoreImplementation::~QFontDatabaseS60StoreImplementation() + +QSymbianFontDatabaseExtrasImplementation::~QSymbianFontDatabaseExtrasImplementation() { - typedef QHash<QString, const QFontEngineS60Extensions *>::iterator iterator; - for (iterator p = m_extensions.begin(); p != m_extensions.end(); ++p) { + typedef QList<const QSymbianTypeFaceExtras *>::iterator iterator; + for (iterator p = m_extras.begin(); p != m_extras.end(); ++p) { m_store->ReleaseFont((*p)->fontOwner()); delete *p; } @@ -156,13 +161,18 @@ COpenFont* OpenFontFromBitmapFont(const CBitmapFont* aBitmapFont) } #endif // FNTSTORE_H_INLINES_SUPPORT_FMM -const QFontEngineS60Extensions *QFontDatabaseS60StoreImplementation::extension(const QString &typeface) const +const QSymbianTypeFaceExtras *QSymbianFontDatabaseExtrasImplementation::extras(const QString &typeface, + bool bold, bool italic) const { - if (!m_extensions.contains(typeface)) { + const QString searchKey = typeface + QString::number(int(bold)) + QString::number(int(italic)); + if (!m_extrasHash.contains(searchKey)) { CFont* font = NULL; - TFontSpec spec(qt_QString2TPtrC(typeface), 1); - spec.iHeight = 1; - const TInt err = m_store->GetNearestFontToDesignHeightInPixels(font, spec); + TFontSpec searchSpec(qt_QString2TPtrC(typeface), 1); + if (bold) + searchSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold); + if (italic) + searchSpec.iFontStyle.SetPosture(EPostureItalic); + const TInt err = m_store->GetNearestFontToDesignHeightInPixels(font, searchSpec); Q_ASSERT(err == KErrNone && font); const CBitmapFont *bitmapFont = static_cast<CBitmapFont*>(font); COpenFont *openFont = @@ -171,9 +181,20 @@ const QFontEngineS60Extensions *QFontDatabaseS60StoreImplementation::extension(c #else OpenFontFromBitmapFont(bitmapFont); #endif // FNTSTORE_H_INLINES_SUPPORT_FMM - m_extensions.insert(typeface, new QFontEngineS60Extensions(font, openFont)); + const TOpenFontFaceAttrib* const attrib = openFont->FaceAttrib(); + const QString foundKey = + QString((const QChar*)attrib->FullName().Ptr(), attrib->FullName().Length()); + if (!m_extrasHash.contains(foundKey)) { + QSymbianTypeFaceExtras *extras = new QSymbianTypeFaceExtras(font, openFont); + m_extras.append(extras); + m_extrasHash.insert(searchKey, extras); + m_extrasHash.insert(foundKey, extras); + } else { + m_store->ReleaseFont(font); + m_extrasHash.insert(searchKey, m_extrasHash.value(foundKey)); + } } - return m_extensions.value(typeface); + return m_extrasHash.value(searchKey); } #else class QFontEngineFTS60 : public QFontEngineFT @@ -240,14 +261,14 @@ static void initializeDb() return; #if defined(QT_NO_FREETYPE) - if (!db->s60Store) - db->s60Store = new QFontDatabaseS60StoreImplementation; + if (!db->symbianExtras) + db->symbianExtras = new QSymbianFontDatabaseExtrasImplementation; QSymbianFbsHeapLock lock(QSymbianFbsHeapLock::Unlock); const int numTypeFaces = QS60Data::screenDevice()->NumTypefaces(); - const QFontDatabaseS60StoreImplementation *store = - static_cast<const QFontDatabaseS60StoreImplementation*>(db->s60Store); + const QSymbianFontDatabaseExtrasImplementation *dbExtras = + static_cast<const QSymbianFontDatabaseExtrasImplementation*>(db->symbianExtras); bool fontAdded = false; for (int i = 0; i < numTypeFaces; i++) { TTypefaceSupport typefaceSupport; @@ -273,8 +294,9 @@ static void initializeDb() style->smoothScalable = typefaceSupport.iIsScalable; style->pixelSize(0, true); - const QFontEngineS60Extensions *extension = store->extension(familyName); - const QByteArray os2Table = extension->getSfntTable(MAKE_TAG('O', 'S', '/', '2')); + 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<const unsigned char*>(os2Table.constData()); const unsigned char* ulUnicodeRange = data + 42; quint32 unicodeRange[4] = { @@ -394,10 +416,11 @@ QFontEngine *QFontDatabase::findFont(int script, const QFontPrivate *, const QFo QFontDef request = req; request.family = fontFamily; #if defined(QT_NO_FREETYPE) - const QFontDatabaseS60StoreImplementation *store = - static_cast<const QFontDatabaseS60StoreImplementation*>(db->s60Store); - const QFontEngineS60Extensions *extension = store->extension(fontFamily); - fe = new QFontEngineS60(request, extension); + const QSymbianFontDatabaseExtrasImplementation *dbExtras = + static_cast<const QSymbianFontDatabaseExtrasImplementation*>(db->symbianExtras); + const QSymbianTypeFaceExtras *typeFaceExtras = + dbExtras->extras(fontFamily, request.weight > QFont::Normal, request.style != QFont::StyleNormal); + fe = new QFontEngineS60(request, typeFaceExtras); #else QFontEngine::FaceId faceId; const QtFontFamily * const reqQtFontFamily = db->family(fontFamily); diff --git a/src/gui/text/qfontengine_s60.cpp b/src/gui/text/qfontengine_s60.cpp index c9ff661..93f02ff 100644 --- a/src/gui/text/qfontengine_s60.cpp +++ b/src/gui/text/qfontengine_s60.cpp @@ -53,22 +53,19 @@ QT_BEGIN_NAMESPACE -QFontEngineS60Extensions::QFontEngineS60Extensions(CFont* fontOwner, COpenFont *font) +QSymbianTypeFaceExtras::QSymbianTypeFaceExtras(CFont* fontOwner, COpenFont *font) : m_font(font) , m_cmap(0) , m_symbolCMap(false) , m_fontOwner(fontOwner) { - TAny *shapingExtension = NULL; - m_font->ExtendedInterface(KUidOpenFontShapingExtension, shapingExtension); - m_shapingExtension = static_cast<MOpenFontShapingExtension*>(shapingExtension); TAny *trueTypeExtension = NULL; m_font->ExtendedInterface(KUidOpenFontTrueTypeExtension, trueTypeExtension); m_trueTypeExtension = static_cast<MOpenFontTrueTypeExtension*>(trueTypeExtension); - Q_ASSERT(m_shapingExtension && m_trueTypeExtension); + Q_ASSERT(m_trueTypeExtension); } -QByteArray QFontEngineS60Extensions::getSfntTable(uint tag) const +QByteArray QSymbianTypeFaceExtras::getSfntTable(uint tag) const { Q_ASSERT(m_trueTypeExtension->HasTrueTypeTable(tag)); TInt error = KErrNone; @@ -79,7 +76,7 @@ QByteArray QFontEngineS60Extensions::getSfntTable(uint tag) const return result; } -bool QFontEngineS60Extensions::getSfntTableData(uint tag, uchar *buffer, uint *length) const +bool QSymbianTypeFaceExtras::getSfntTableData(uint tag, uchar *buffer, uint *length) const { if (!m_trueTypeExtension->HasTrueTypeTable(tag)) return false; @@ -104,7 +101,7 @@ bool QFontEngineS60Extensions::getSfntTableData(uint tag, uchar *buffer, uint *l return result; } -const unsigned char *QFontEngineS60Extensions::cmap() const +const unsigned char *QSymbianTypeFaceExtras::cmap() const { if (!m_cmap) { m_cmapTable = getSfntTable(MAKE_TAG('c', 'm', 'a', 'p')); @@ -114,27 +111,7 @@ const unsigned char *QFontEngineS60Extensions::cmap() const return m_cmap; } -QPainterPath QFontEngineS60Extensions::glyphOutline(glyph_t glyph) const -{ - QPainterPath result; - QPolygonF polygon; - TInt glyphIndex = glyph; - TInt pointNumber = 0; - TInt x, y; - while (m_shapingExtension->GlyphPointInFontUnits(glyphIndex, pointNumber++, x, y)) { - const QPointF point(qreal(x) / 0xffff, qreal(y) / 0xffff); - if (polygon.contains(point)) { - result.addPolygon(polygon); - result.closeSubpath(); - polygon.clear(); - } else { - polygon.append(point); - } - } - return result; -} - -CFont *QFontEngineS60Extensions::fontOwner() const +CFont *QSymbianTypeFaceExtras::fontOwner() const { return m_fontOwner; } @@ -192,8 +169,8 @@ void QFontEngineS60::releaseFont(CFont *&font) } } -QFontEngineS60::QFontEngineS60(const QFontDef &request, const QFontEngineS60Extensions *extensions) - : m_extensions(extensions) +QFontEngineS60::QFontEngineS60(const QFontDef &request, const QSymbianTypeFaceExtras *extras) + : m_extras(extras) , m_originalFont(0) , m_originalFontSizeInPixels((request.pixelSize >= 0)? request.pixelSize:pointsToPixels(request.pointSize)) @@ -220,10 +197,12 @@ bool QFontEngineS60::stringToCMap(const QChar *characters, int len, QGlyphLayout } HB_Glyph *g = glyphs->glyphs; - const unsigned char* cmap = m_extensions->cmap(); + const unsigned char* cmap = m_extras->cmap(); + const bool isRtl = (flags & QTextEngine::RightToLeft); for (int i = 0; i < len; ++i) { const unsigned int uc = getChar(characters, i, len); - *g++ = QFontEngine::getTrueTypeGlyphIndex(cmap, uc); + *g++ = QFontEngine::getTrueTypeGlyphIndex(cmap, + isRtl ? QChar::mirroredChar(uc) : uc); } glyphs->numGlyphs = g - glyphs->glyphs; @@ -241,8 +220,8 @@ void QFontEngineS60::recalcAdvances(QGlyphLayout *glyphs, QTextEngine::ShaperFla Q_UNUSED(flags); for (int i = 0; i < glyphs->numGlyphs; i++) { const glyph_metrics_t bbox = boundingBox_const(glyphs->glyphs[i]); - glyphs->advances_x[i] = glyphs->offsets[i].x = bbox.xoff; - glyphs->advances_y[i] = glyphs->offsets[i].y = bbox.yoff; + glyphs->advances_x[i] = bbox.xoff; + glyphs->advances_y[i] = bbox.yoff; } } @@ -337,7 +316,7 @@ const char *QFontEngineS60::name() const bool QFontEngineS60::canRender(const QChar *string, int len) { - const unsigned char *cmap = m_extensions->cmap(); + const unsigned char *cmap = m_extras->cmap(); for (int i = 0; i < len; ++i) { const unsigned int uc = getChar(string, i, len); if (QFontEngine::getTrueTypeGlyphIndex(cmap, uc) == 0) @@ -348,12 +327,12 @@ bool QFontEngineS60::canRender(const QChar *string, int len) QByteArray QFontEngineS60::getSfntTable(uint tag) const { - return m_extensions->getSfntTable(tag); + return m_extras->getSfntTable(tag); } bool QFontEngineS60::getSfntTableData(uint tag, uchar *buffer, uint *length) const { - return m_extensions->getSfntTableData(tag, buffer, length); + return m_extras->getSfntTableData(tag, buffer, length); } QFontEngine::Type QFontEngineS60::type() const diff --git a/src/gui/text/qfontengine_s60_p.h b/src/gui/text/qfontengine_s60_p.h index a80af4d..6883730 100644 --- a/src/gui/text/qfontengine_s60_p.h +++ b/src/gui/text/qfontengine_s60_p.h @@ -62,21 +62,19 @@ class CFont; QT_BEGIN_NAMESPACE -// ..gives us access to truetype tables, UTF-16<->GlyphID mapping, and glyph outlines -class QFontEngineS60Extensions +// ..gives us access to truetype tables +class QSymbianTypeFaceExtras { public: - QFontEngineS60Extensions(CFont* fontOwner, COpenFont *font); + QSymbianTypeFaceExtras(CFont* fontOwner, COpenFont *font); QByteArray getSfntTable(uint tag) const; bool getSfntTableData(uint tag, uchar *buffer, uint *length) const; const unsigned char *cmap() const; - QPainterPath glyphOutline(glyph_t glyph) const; CFont *fontOwner() const; private: COpenFont *m_font; - const MOpenFontShapingExtension *m_shapingExtension; mutable MOpenFontTrueTypeExtension *m_trueTypeExtension; mutable const unsigned char *m_cmap; mutable bool m_symbolCMap; @@ -87,7 +85,7 @@ private: class QFontEngineS60 : public QFontEngine { public: - QFontEngineS60(const QFontDef &fontDef, const QFontEngineS60Extensions *extensions); + QFontEngineS60(const QFontDef &fontDef, const QSymbianTypeFaceExtras *extras); ~QFontEngineS60(); bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const; @@ -128,7 +126,7 @@ private: CFont *fontWithSize(qreal size) const; static void releaseFont(CFont *&font); - const QFontEngineS60Extensions *m_extensions; + const QSymbianTypeFaceExtras *m_extras; CFont* m_originalFont; const qreal m_originalFontSizeInPixels; CFont* m_scaledFont; diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index 3e556a7..afba678 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -1704,7 +1704,7 @@ void QTextDocument::print(QPrinter *printer) const return; const QTextDocument *doc = this; - QTextDocument *clonedDoc = 0; + QScopedPointer<QTextDocument> clonedDoc; (void)doc->documentLayout(); // make sure that there is a layout QRectF body = QRectF(QPointF(0, 0), d->pageSize); @@ -1737,7 +1737,7 @@ void QTextDocument::print(QPrinter *printer) const printerPageSize.height() / scaledPageSize.height()); } else { doc = clone(const_cast<QTextDocument *>(this)); - clonedDoc = const_cast<QTextDocument *>(doc); + clonedDoc.reset(const_cast<QTextDocument *>(doc)); for (QTextBlock srcBlock = firstBlock(), dstBlock = clonedDoc->firstBlock(); srcBlock.isValid() && dstBlock.isValid(); @@ -1812,7 +1812,7 @@ void QTextDocument::print(QPrinter *printer) const for (int j = 0; j < pageCopies; ++j) { if (printer->printerState() == QPrinter::Aborted || printer->printerState() == QPrinter::Error) - goto UserCanceled; + return; printPage(page, &p, doc, body, pageNumberPos); if (j < pageCopies - 1) printer->newPage(); @@ -1832,9 +1832,6 @@ void QTextDocument::print(QPrinter *printer) const if ( i < docCopies - 1) printer->newPage(); } - -UserCanceled: - delete clonedDoc; } #endif |