diff options
Diffstat (limited to 'src/gui/text')
-rw-r--r-- | src/gui/text/qfontdatabase_s60.cpp | 76 | ||||
-rw-r--r-- | src/gui/text/qfontengine_ft.cpp | 15 | ||||
-rw-r--r-- | src/gui/text/qfontengine_ft_p.h | 1 | ||||
-rw-r--r-- | src/gui/text/qfontengine_s60.cpp | 172 | ||||
-rw-r--r-- | src/gui/text/qfontengine_s60_p.h | 25 | ||||
-rw-r--r-- | src/gui/text/qstatictext.cpp | 37 | ||||
-rw-r--r-- | src/gui/text/qstatictext_p.h | 7 | ||||
-rw-r--r-- | src/gui/text/qtextcursor.cpp | 87 | ||||
-rw-r--r-- | src/gui/text/qtextcursor.h | 6 | ||||
-rw-r--r-- | src/gui/text/qtextcursor_p.h | 3 | ||||
-rw-r--r-- | src/gui/text/qtextdocumentlayout.cpp | 58 | ||||
-rw-r--r-- | src/gui/text/qtextlayout.cpp | 4 | ||||
-rw-r--r-- | src/gui/text/qtextoption.cpp | 10 | ||||
-rw-r--r-- | src/gui/text/qtextoption.h | 2 | ||||
-rw-r--r-- | src/gui/text/text.pri | 3 |
15 files changed, 410 insertions, 96 deletions
diff --git a/src/gui/text/qfontdatabase_s60.cpp b/src/gui/text/qfontdatabase_s60.cpp index 489b70b..943df7f 100644 --- a/src/gui/text/qfontdatabase_s60.cpp +++ b/src/gui/text/qfontdatabase_s60.cpp @@ -49,12 +49,12 @@ #include <private/qt_s60_p.h> #include "qendian.h" #include <private/qcore_symbian_p.h> -#if defined(QT_NO_FREETYPE) +#ifdef QT_NO_FREETYPE #include <openfont.h> #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS #include <graphics/openfontrasterizer.h> // COpenFontRasterizer has moved to a new header file #endif // SYMBIAN_ENABLE_SPLIT_HEADERS -#endif +#endif // QT_NO_FREETYPE QT_BEGIN_NAMESPACE @@ -91,7 +91,7 @@ QFileInfoList alternativeFilePaths(const QString &path, const QStringList &nameF return result; } -#if defined(QT_NO_FREETYPE) +#ifdef QT_NO_FREETYPE class QSymbianFontDatabaseExtrasImplementation : public QSymbianFontDatabaseExtras { public: @@ -100,16 +100,41 @@ public: const QSymbianTypeFaceExtras *extras(const QString &typeface, bool bold, bool italic) const; +#ifndef Q_SYMBIAN_HAS_FONTTABLE_API + struct CFontFromFontStoreReleaser { + static inline void cleanup(CFont *font) + { + if (!font) + return; + const QSymbianFontDatabaseExtrasImplementation *dbExtras = + static_cast<const QSymbianFontDatabaseExtrasImplementation*>(privateDb()->symbianExtras); + dbExtras->m_store->ReleaseFont(font); + } + }; +#endif // !Q_SYMBIAN_HAS_FONTTABLE_API + + struct CFontFromScreenDeviceReleaser { + static inline void cleanup(CFont *font) + { + if (!font) + return; + QS60Data::screenDevice()->ReleaseFont(font); + } + }; + private: +#ifndef Q_SYMBIAN_HAS_FONTTABLE_API RHeap* m_heap; CFontStore *m_store; COpenFontRasterizer *m_rasterizer; mutable QList<const QSymbianTypeFaceExtras *> m_extras; +#endif // !Q_SYMBIAN_HAS_FONTTABLE_API mutable QHash<QString, const QSymbianTypeFaceExtras *> m_extrasHash; }; QSymbianFontDatabaseExtrasImplementation::QSymbianFontDatabaseExtrasImplementation() { +#ifndef Q_SYMBIAN_HAS_FONTTABLE_API QStringList filters; filters.append(QLatin1String("*.ttf")); filters.append(QLatin1String("*.ccc")); @@ -131,10 +156,14 @@ QSymbianFontDatabaseExtrasImplementation::QSymbianFontDatabaseExtrasImplementati TPtrC fontFilePtr(qt_QString2TPtrC(fontFile)); QT_TRAP_THROWING(m_store->AddFileL(fontFilePtr)); } +#endif // !Q_SYMBIAN_HAS_FONTTABLE_API } QSymbianFontDatabaseExtrasImplementation::~QSymbianFontDatabaseExtrasImplementation() { +#ifdef Q_SYMBIAN_HAS_FONTTABLE_API + qDeleteAll(m_extrasHash); +#else // Q_SYMBIAN_HAS_FONTTABLE_API typedef QList<const QSymbianTypeFaceExtras *>::iterator iterator; for (iterator p = m_extras.begin(); p != m_extras.end(); ++p) { m_store->ReleaseFont((*p)->fontOwner()); @@ -143,6 +172,7 @@ QSymbianFontDatabaseExtrasImplementation::~QSymbianFontDatabaseExtrasImplementat delete m_store; m_heap->Close(); +#endif // Q_SYMBIAN_HAS_FONTTABLE_API } #ifndef FNTSTORE_H_INLINES_SUPPORT_FMM @@ -167,26 +197,37 @@ const QSymbianTypeFaceExtras *QSymbianFontDatabaseExtrasImplementation::extras(c { const QString searchKey = typeface + QString::number(int(bold)) + QString::number(int(italic)); if (!m_extrasHash.contains(searchKey)) { - CFont* font = NULL; TFontSpec searchSpec(qt_QString2TPtrC(typeface), 1); if (bold) searchSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold); if (italic) searchSpec.iFontStyle.SetPosture(EPostureItalic); + + CFont* font = NULL; +#ifdef Q_SYMBIAN_HAS_FONTTABLE_API + const TInt err = QS60Data::screenDevice()->GetNearestFontToDesignHeightInPixels(font, searchSpec); + Q_ASSERT(err == KErrNone && font); + QScopedPointer<CFont, CFontFromScreenDeviceReleaser> sFont(font); + QSymbianTypeFaceExtras *extras = new QSymbianTypeFaceExtras(font); + sFont.take(); + m_extrasHash.insert(searchKey, extras); +#else // Q_SYMBIAN_HAS_FONTTABLE_API const TInt err = m_store->GetNearestFontToDesignHeightInPixels(font, searchSpec); Q_ASSERT(err == KErrNone && font); const CBitmapFont *bitmapFont = static_cast<CBitmapFont*>(font); COpenFont *openFont = #ifdef FNTSTORE_H_INLINES_SUPPORT_FMM - bitmapFont->openFont(); -#else + bitmapFont->OpenFont(); +#else // FNTSTORE_H_INLINES_SUPPORT_FMM OpenFontFromBitmapFont(bitmapFont); #endif // FNTSTORE_H_INLINES_SUPPORT_FMM const TOpenFontFaceAttrib* const attrib = openFont->FaceAttrib(); const QString foundKey = QString((const QChar*)attrib->FullName().Ptr(), attrib->FullName().Length()); if (!m_extrasHash.contains(foundKey)) { + QScopedPointer<CFont, CFontFromFontStoreReleaser> sFont(font); QSymbianTypeFaceExtras *extras = new QSymbianTypeFaceExtras(font, openFont); + sFont.take(); m_extras.append(extras); m_extrasHash.insert(searchKey, extras); m_extrasHash.insert(foundKey, extras); @@ -194,10 +235,11 @@ const QSymbianTypeFaceExtras *QSymbianFontDatabaseExtrasImplementation::extras(c m_store->ReleaseFont(font); m_extrasHash.insert(searchKey, m_extrasHash.value(foundKey)); } +#endif // Q_SYMBIAN_HAS_FONTTABLE_API } return m_extrasHash.value(searchKey); } -#else +#else // QT_NO_FREETYPE class QFontEngineFTS60 : public QFontEngineFT { public: @@ -209,7 +251,7 @@ QFontEngineFTS60::QFontEngineFTS60(const QFontDef &fd) { default_hint_style = HintFull; } -#endif // defined(QT_NO_FREETYPE) +#endif // QT_NO_FREETYPE /* QFontEngineS60::pixelsToPoints, QFontEngineS60::pointsToPixels, QFontEngineMultiS60::QFontEngineMultiS60 @@ -261,12 +303,12 @@ static void initializeDb() if(!db || db->count) return; -#if defined(QT_NO_FREETYPE) +#ifdef QT_NO_FREETYPE if (!db->symbianExtras) db->symbianExtras = new QSymbianFontDatabaseExtrasImplementation; QSymbianFbsHeapLock lock(QSymbianFbsHeapLock::Unlock); - + const int numTypeFaces = QS60Data::screenDevice()->NumTypefaces(); const QSymbianFontDatabaseExtrasImplementation *dbExtras = static_cast<const QSymbianFontDatabaseExtrasImplementation*>(db->symbianExtras); @@ -278,6 +320,7 @@ static void initializeDb() TFontSpec fontSpec(typefaceSupport.iTypeface.iName, 11); if (QS60Data::screenDevice()->GetNearestFontInPixels(font, fontSpec) != KErrNone) continue; + QScopedPointer<CFont, QSymbianFontDatabaseExtrasImplementation::CFontFromScreenDeviceReleaser> sFont(font); if (font->TypeUid() == KCFbsFontUid) { TOpenFontFaceAttrib faceAttrib; const CFbsFont *cfbsFont = static_cast<const CFbsFont *>(font); @@ -318,14 +361,13 @@ static void initializeDb() fontAdded = true; } - QS60Data::screenDevice()->ReleaseFont(font); } Q_ASSERT(fontAdded); - lock.relock(); + lock.relock(); -#else // defined(QT_NO_FREETYPE) +#else // QT_NO_FREETYPE QDir dir(QDesktopServices::storageLocation(QDesktopServices::FontsLocation)); dir.setNameFilters(QStringList() << QLatin1String("*.ttf") << QLatin1String("*.ttc") << QLatin1String("*.pfa") @@ -334,7 +376,7 @@ static void initializeDb() const QByteArray file = QFile::encodeName(dir.absoluteFilePath(dir[i])); db->addTTFile(file); } -#endif // defined(QT_NO_FREETYPE) +#endif // QT_NO_FREETYPE } static inline void load(const QString &family = QString(), int script = -1) @@ -416,13 +458,13 @@ QFontEngine *QFontDatabase::findFont(int script, const QFontPrivate *, const QFo const QString fontFamily = desc.family->name; QFontDef request = req; request.family = fontFamily; -#if defined(QT_NO_FREETYPE) +#ifdef QT_NO_FREETYPE 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 +#else // QT_NO_FREETYPE QFontEngine::FaceId faceId; const QtFontFamily * const reqQtFontFamily = db->family(fontFamily); faceId.filename = reqQtFontFamily->fontFilename; @@ -433,7 +475,7 @@ QFontEngine *QFontDatabase::findFont(int script, const QFontPrivate *, const QFo fe = fte; else delete fte; -#endif +#endif // QT_NO_FREETYPE Q_ASSERT(fe); if (script == QUnicodeTables::Common diff --git a/src/gui/text/qfontengine_ft.cpp b/src/gui/text/qfontengine_ft.cpp index 449dffd..9056012 100644 --- a/src/gui/text/qfontengine_ft.cpp +++ b/src/gui/text/qfontengine_ft.cpp @@ -58,6 +58,7 @@ #include <ft2build.h> #include FT_FREETYPE_H #include FT_OUTLINE_H +#include FT_SYNTHESIS_H #include FT_TRUETYPE_TABLES_H #include FT_TYPE1_TABLES_H #include FT_GLYPH_H @@ -617,6 +618,7 @@ QFontEngineFT::QFontEngineFT(const QFontDef &fd) cache_cost = 100; kerning_pairs_loaded = false; transform = false; + embolden = false; antialias = true; freetype = 0; default_load_flags = FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH; @@ -679,10 +681,7 @@ bool QFontEngineFT::init(FaceId faceId, bool antialias, GlyphFormat format) FT_Face face = lockFace(); - //underline metrics if (FT_IS_SCALABLE(face)) { - line_thickness = QFixed::fromFixed(FT_MulFix(face->underline_thickness, face->size->metrics.y_scale)); - underline_position = QFixed::fromFixed(-FT_MulFix(face->underline_position, face->size->metrics.y_scale)); bool fake_oblique = (fontDef.style != QFont::StyleNormal) && !(face->style_flags & FT_STYLE_FLAG_ITALIC); if (fake_oblique) matrix.xy = 0x10000*3/10; @@ -690,6 +689,12 @@ bool QFontEngineFT::init(FaceId faceId, bool antialias, GlyphFormat format) freetype->matrix = matrix; if (fake_oblique) transform = true; + // fake bold + if ((fontDef.weight == QFont::Bold) && !(face->style_flags & FT_STYLE_FLAG_BOLD)) + embolden = true; + // underline metrics + line_thickness = QFixed::fromFixed(FT_MulFix(face->underline_thickness, face->size->metrics.y_scale)); + underline_position = QFixed::fromFixed(-FT_MulFix(face->underline_position, face->size->metrics.y_scale)); } else { // copied from QFontEngineQPF // ad hoc algorithm @@ -789,6 +794,7 @@ QFontEngineFT::Glyph *QFontEngineFT::loadGlyphMetrics(QGlyphSet *set, uint glyph } FT_GlyphSlot slot = face->glyph; + if (embolden) FT_GlyphSlot_Embolden(slot); int left = slot->metrics.horiBearingX; int right = slot->metrics.horiBearingX + slot->metrics.width; int top = slot->metrics.horiBearingY; @@ -934,6 +940,7 @@ QFontEngineFT::Glyph *QFontEngineFT::loadGlyph(QGlyphSet *set, uint glyph, Glyph return 0; FT_GlyphSlot slot = face->glyph; + if (embolden) FT_GlyphSlot_Embolden(slot); FT_Library library = qt_getFreetype(); info.xOff = TRUNC(ROUND(slot->advance.x)); @@ -1209,6 +1216,8 @@ int QFontEngineFT::synthesized() const int s = 0; if ((fontDef.style != QFont::StyleNormal) && !(freetype->face->style_flags & FT_STYLE_FLAG_ITALIC)) s = SynthesizedItalic; + if ((fontDef.weight == QFont::Bold) && !(freetype->face->style_flags & FT_STYLE_FLAG_BOLD)) + s |= SynthesizedBold; if (fontDef.stretch != 100 && FT_IS_SCALABLE(freetype->face)) s |= SynthesizedStretch; return s; diff --git a/src/gui/text/qfontengine_ft_p.h b/src/gui/text/qfontengine_ft_p.h index 12b7da8..2f05a8b 100644 --- a/src/gui/text/qfontengine_ft_p.h +++ b/src/gui/text/qfontengine_ft_p.h @@ -304,6 +304,7 @@ protected: bool antialias; bool transform; + bool embolden; SubpixelAntialiasingType subpixelType; int lcdFilterType; bool canUploadGlyphsToServer; diff --git a/src/gui/text/qfontengine_s60.cpp b/src/gui/text/qfontengine_s60.cpp index 93f02ff..925b3bf 100644 --- a/src/gui/text/qfontengine_s60.cpp +++ b/src/gui/text/qfontengine_s60.cpp @@ -50,21 +50,73 @@ #include <e32std.h> #include <eikenv.h> #include <gdi.h> +#if defined(Q_SYMBIAN_HAS_FONTTABLE_API) || defined(Q_SYMBIAN_HAS_GLYPHOUTLINE_API) +#include <graphics/gdi/gdiplatapi.h> +#endif // Q_SYMBIAN_HAS_FONTTABLE_API || Q_SYMBIAN_HAS_GLYPHOUTLINE_API QT_BEGIN_NAMESPACE -QSymbianTypeFaceExtras::QSymbianTypeFaceExtras(CFont* fontOwner, COpenFont *font) - : m_font(font) - , m_cmap(0) +#ifdef Q_SYMBIAN_HAS_FONTTABLE_API +QSymbianTypeFaceExtras::QSymbianTypeFaceExtras(CFont* cFont, COpenFont *openFont) + : m_cFont(cFont) , m_symbolCMap(false) - , m_fontOwner(fontOwner) +{ + Q_UNUSED(openFont) +} + +QSymbianTypeFaceExtras::~QSymbianTypeFaceExtras() +{ + QS60Data::screenDevice()->ReleaseFont(m_cFont); +} + +QByteArray QSymbianTypeFaceExtras::getSfntTable(uint tag) const +{ + RFontTable fontTable; + if (fontTable.Open(*m_cFont, tag) != KErrNone) + return QByteArray(); + const QByteArray byteArray(reinterpret_cast<const char *> + (fontTable.TableContent()),fontTable.TableLength()); + fontTable.Close(); + return byteArray; +} + +bool QSymbianTypeFaceExtras::getSfntTableData(uint tag, uchar *buffer, uint *length) const +{ + RFontTable fontTable; + if (fontTable.Open(*m_cFont, tag) != KErrNone) + return false; + + bool result = true; + const TInt tableByteLength = fontTable.TableLength(); + + if (*length > 0 && *length < tableByteLength) { + result = false; // Caller did not allocate enough memory + } else { + *length = tableByteLength; + if (buffer) + qMemCopy(buffer, fontTable.TableContent(), tableByteLength); + } + + fontTable.Close(); + return result; +} + +#else // Q_SYMBIAN_HAS_FONTTABLE_API +QSymbianTypeFaceExtras::QSymbianTypeFaceExtras(CFont* cFont, COpenFont *openFont) + : m_cFont(cFont) + , m_symbolCMap(false) + , m_openFont(openFont) { TAny *trueTypeExtension = NULL; - m_font->ExtendedInterface(KUidOpenFontTrueTypeExtension, trueTypeExtension); + m_openFont->ExtendedInterface(KUidOpenFontTrueTypeExtension, trueTypeExtension); m_trueTypeExtension = static_cast<MOpenFontTrueTypeExtension*>(trueTypeExtension); Q_ASSERT(m_trueTypeExtension); } +QSymbianTypeFaceExtras::~QSymbianTypeFaceExtras() +{ +} + QByteArray QSymbianTypeFaceExtras::getSfntTable(uint tag) const { Q_ASSERT(m_trueTypeExtension->HasTrueTypeTable(tag)); @@ -100,23 +152,25 @@ bool QSymbianTypeFaceExtras::getSfntTableData(uint tag, uchar *buffer, uint *len m_trueTypeExtension->ReleaseTrueTypeTable(table); return result; } +#endif // Q_SYMBIAN_HAS_FONTTABLE_API -const unsigned char *QSymbianTypeFaceExtras::cmap() const +const uchar *QSymbianTypeFaceExtras::cmap() const { - if (!m_cmap) { - m_cmapTable = getSfntTable(MAKE_TAG('c', 'm', 'a', 'p')); + if (m_cmapTable.isNull()) { + const QByteArray cmapTable = getSfntTable(MAKE_TAG('c', 'm', 'a', 'p')); int size = 0; - m_cmap = QFontEngineS60::getCMap(reinterpret_cast<const uchar *>(m_cmapTable.constData()), m_cmapTable.size(), &m_symbolCMap, &size); + const uchar *cmap = QFontEngine::getCMap(reinterpret_cast<const uchar *> + (cmapTable.constData()), cmapTable.size(), &m_symbolCMap, &size); + m_cmapTable = QByteArray(reinterpret_cast<const char *>(cmap), size); } - return m_cmap; + return reinterpret_cast<const uchar *>(m_cmapTable.constData()); } CFont *QSymbianTypeFaceExtras::fontOwner() const { - return m_fontOwner; + return m_cFont; } - // duplicated from qfontengine_xyz.cpp static inline unsigned int getChar(const QChar *str, int &i, const int len) { @@ -225,6 +279,35 @@ void QFontEngineS60::recalcAdvances(QGlyphLayout *glyphs, QTextEngine::ShaperFla } } +#ifdef Q_SYMBIAN_HAS_GLYPHOUTLINE_API +static bool parseGlyphPathData(const char *dataStr, const char *dataEnd, QPainterPath &path, + qreal fontPixelSize, const QPointF &offset, bool hinted); +#endif //Q_SYMBIAN_HAS_GLYPHOUTLINE_API + +void QFontEngineS60::addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, + int nglyphs, QPainterPath *path, + QTextItem::RenderFlags flags) +{ +#ifdef Q_SYMBIAN_HAS_GLYPHOUTLINE_API + Q_UNUSED(flags) + RGlyphOutlineIterator iterator; + const TInt error = iterator.Open(*m_activeFont, glyphs, nglyphs); + if (KErrNone != error) + return; + const qreal fontSizeInPixels = qreal(m_activeFont->HeightInPixels()); + int count = 0; + do { + const TUint8* outlineUint8 = iterator.Outline(); + const char* const outlineChar = reinterpret_cast<const char*>(outlineUint8); + const char* const outlineEnd = outlineChar + iterator.OutlineLength(); + parseGlyphPathData(outlineChar, outlineEnd, *path, fontSizeInPixels, + positions[count++].toPointF(), false); + } while(KErrNone == iterator.Next() && count <= nglyphs); +#else // Q_SYMBIAN_HAS_GLYPHOUTLINE_API + QFontEngine::addGlyphsToPath(glyphs, positions, nglyphs, path, flags); +#endif //Q_SYMBIAN_HAS_GLYPHOUTLINE_API +} + QImage QFontEngineS60::alphaMapForGlyph(glyph_t glyph) { TOpenFontCharMetrics metrics; @@ -356,4 +439,69 @@ void QFontEngineS60::getCharacterData(glyph_t glyph, TOpenFontCharMetrics& metri } } +#ifdef Q_SYMBIAN_HAS_GLYPHOUTLINE_API +static inline void skipSpacesAndComma(const char* &str, const char* const strEnd) +{ + while (str <= strEnd && (*str == ' ' || *str == ',')) + ++str; +} + +static bool parseGlyphPathData(const char *svgPath, const char *svgPathEnd, QPainterPath &path, + qreal fontPixelSize, const QPointF &offset, bool hinted) +{ + Q_UNUSED(hinted) + QPointF p1, p2, firstSubPathPoint; + qreal *elementValues[] = + {&p1.rx(), &p1.ry(), &p2.rx(), &p2.ry()}; + const int unitsPerEm = 2048; // See: http://en.wikipedia.org/wiki/Em_%28typography%29 + const qreal resizeFactor = fontPixelSize / unitsPerEm; + + while (svgPath < svgPathEnd) { + skipSpacesAndComma(svgPath, svgPathEnd); + const char pathElem = *svgPath++; + skipSpacesAndComma(svgPath, svgPathEnd); + + if (pathElem != 'Z') { + char *endStr = 0; + int elementValuesCount = 0; + for (int i = 0; i < 4; ++i) { // 4 = size of elementValues[] + qreal coordinateValue = strtod(svgPath, &endStr); + if (svgPath == endStr) + break; + if (i % 2) // Flip vertically + coordinateValue = -coordinateValue; + *elementValues[i] = coordinateValue * resizeFactor; + elementValuesCount++; + svgPath = endStr; + skipSpacesAndComma(svgPath, svgPathEnd); + } + p1 += offset; + if (elementValuesCount == 2) + p2 = firstSubPathPoint; + else + p2 += offset; + } + + switch (pathElem) { + case 'M': + firstSubPathPoint = p1; + path.moveTo(p1); + break; + case 'Z': + path.closeSubpath(); + break; + case 'L': + path.lineTo(p1); + break; + case 'Q': + path.quadTo(p1, p2); + break; + default: + return false; + } + } + return true; +} +#endif // Q_SYMBIAN_HAS_GLYPHOUTLINE_API + QT_END_NAMESPACE diff --git a/src/gui/text/qfontengine_s60_p.h b/src/gui/text/qfontengine_s60_p.h index 6883730..beeb4cc 100644 --- a/src/gui/text/qfontengine_s60_p.h +++ b/src/gui/text/qfontengine_s60_p.h @@ -58,6 +58,14 @@ #include "qsize.h" #include <openfont.h> +#ifdef SYMBIAN_GDI_GLYPHDATA +#define Q_SYMBIAN_HAS_FONTTABLE_API +#endif + +#ifdef Q_SYMBIAN_HAS_FONTTABLE_API +#define Q_SYMBIAN_HAS_GLYPHOUTLINE_API +#endif // Q_SYMBIAN_HAS_FONTTABLE_API + class CFont; QT_BEGIN_NAMESPACE @@ -66,20 +74,22 @@ QT_BEGIN_NAMESPACE class QSymbianTypeFaceExtras { public: - QSymbianTypeFaceExtras(CFont* fontOwner, COpenFont *font); + QSymbianTypeFaceExtras(CFont* cFont, COpenFont *openFont = 0); + ~QSymbianTypeFaceExtras(); QByteArray getSfntTable(uint tag) const; bool getSfntTableData(uint tag, uchar *buffer, uint *length) const; - const unsigned char *cmap() const; + const uchar *cmap() const; CFont *fontOwner() const; private: - COpenFont *m_font; - mutable MOpenFontTrueTypeExtension *m_trueTypeExtension; - mutable const unsigned char *m_cmap; + CFont* m_cFont; mutable bool m_symbolCMap; mutable QByteArray m_cmapTable; - CFont* m_fontOwner; +#ifndef Q_SYMBIAN_HAS_FONTTABLE_API + COpenFont *m_openFont; + mutable MOpenFontTrueTypeExtension *m_trueTypeExtension; +#endif // Q_SYMBIAN_HAS_FONTTABLE_API }; class QFontEngineS60 : public QFontEngine @@ -91,6 +101,9 @@ public: bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const; void recalcAdvances(QGlyphLayout *glyphs, QTextEngine::ShaperFlags flags) const; + void addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, int nglyphs, + QPainterPath *path, QTextItem::RenderFlags flags); + QImage alphaMapForGlyph(glyph_t glyph); glyph_metrics_t boundingBox(const QGlyphLayout &glyphs); diff --git a/src/gui/text/qstatictext.cpp b/src/gui/text/qstatictext.cpp index 84c1d96..10870aa 100644 --- a/src/gui/text/qstatictext.cpp +++ b/src/gui/text/qstatictext.cpp @@ -115,10 +115,12 @@ QT_BEGIN_NAMESPACE Qt::RichText. If it's the first time the static text is drawn, or if the static text, or the painter's font - or matrix have been altered since the last time it was drawn, the text's layout has to be - recalculated. This will impose an overhead on the QPainter::drawStaticText() call where the - relayout occurs. To avoid this overhead in the paint event, you can call prepare() ahead of - time to ensure that the layout is calculated. + has been altered since the last time it was drawn, the text's layout has to be + recalculated. On some paint engines, changing the matrix of the painter will also cause the + layout to be recalculated. In particular, this will happen for any engine except for the + OpenGL2 paint engine. Recalculating the layout will impose an overhead on the + QPainter::drawStaticText() call where it occurs. To avoid this overhead in the paint event, you + can call prepare() ahead of time to ensure that the layout is calculated. \sa QPainter::drawText(), QPainter::drawStaticText(), QTextLayout, QTextDocument */ @@ -188,8 +190,9 @@ void QStaticText::detach() When drawStaticText() is called, the layout of the QStaticText will be recalculated if any part of the QStaticText object has changed since the last time it was drawn. It will also be - recalculated if the painter's font or matrix are not the same as when the QStaticText was last - drawn. + recalculated if the painter's font is not the same as when the QStaticText was last drawn, or, + on any other paint engine than the OpenGL2 engine, if the painter's matrix has been altered + since the static text was last drawn. To avoid the overhead of creating the layout the first time you draw the QStaticText after making changes, you can use the prepare() function and pass in the \a matrix and \a font you @@ -364,14 +367,16 @@ QSizeF QStaticText::size() const QStaticTextPrivate::QStaticTextPrivate() : textWidth(-1.0), items(0), itemCount(0), glyphPool(0), positionPool(0), charPool(0), - needsRelayout(true), useBackendOptimizations(false), textFormat(Qt::AutoText) + needsRelayout(true), useBackendOptimizations(false), textFormat(Qt::AutoText), + untransformedCoordinates(false) { } QStaticTextPrivate::QStaticTextPrivate(const QStaticTextPrivate &other) : text(other.text), font(other.font), textWidth(other.textWidth), matrix(other.matrix), items(0), itemCount(0), glyphPool(0), positionPool(0), charPool(0), needsRelayout(true), - useBackendOptimizations(other.useBackendOptimizations), textFormat(other.textFormat) + useBackendOptimizations(other.useBackendOptimizations), textFormat(other.textFormat), + untransformedCoordinates(other.untransformedCoordinates) { } @@ -396,8 +401,9 @@ namespace { class DrawTextItemRecorder: public QPaintEngine { public: - DrawTextItemRecorder(bool useBackendOptimizations, int numChars) - : m_dirtyPen(false), m_useBackendOptimizations(useBackendOptimizations) + DrawTextItemRecorder(bool untransformedCoordinates, bool useBackendOptimizations, int numChars) + : m_dirtyPen(false), m_useBackendOptimizations(useBackendOptimizations), + m_untransformedCoordinates(untransformedCoordinates) { } @@ -423,7 +429,7 @@ namespace { if (m_dirtyPen) currentItem.color = state->pen().color(); - QTransform matrix = state->transform(); + QTransform matrix = m_untransformedCoordinates ? QTransform() : state->transform(); matrix.translate(position.x(), position.y()); QVarLengthArray<glyph_t> glyphs; @@ -486,14 +492,17 @@ namespace { bool m_dirtyPen; bool m_useBackendOptimizations; + bool m_untransformedCoordinates; }; class DrawTextItemDevice: public QPaintDevice { public: - DrawTextItemDevice(bool useBackendOptimizations, int numChars) + DrawTextItemDevice(bool untransformedCoordinates, bool useBackendOptimizations, + int numChars) { - m_paintEngine = new DrawTextItemRecorder(useBackendOptimizations, numChars); + m_paintEngine = new DrawTextItemRecorder(untransformedCoordinates, + useBackendOptimizations, numChars); } ~DrawTextItemDevice() @@ -629,7 +638,7 @@ void QStaticTextPrivate::init() position = QPointF(0, 0); - DrawTextItemDevice device(useBackendOptimizations, text.size()); + DrawTextItemDevice device(untransformedCoordinates, useBackendOptimizations, text.size()); { QPainter painter(&device); painter.setFont(font); diff --git a/src/gui/text/qstatictext_p.h b/src/gui/text/qstatictext_p.h index 2ab5579..1a96291 100644 --- a/src/gui/text/qstatictext_p.h +++ b/src/gui/text/qstatictext_p.h @@ -148,9 +148,10 @@ public: QFixedPoint *positionPool; // 4 bytes per text QChar *charPool; // 4 bytes per text - unsigned char needsRelayout : 1; - unsigned char useBackendOptimizations : 1; // 1 byte per text - unsigned char textFormat : 2; + unsigned char needsRelayout : 1; // 1 byte per text + unsigned char useBackendOptimizations : 1; + unsigned char textFormat : 2; + unsigned char untransformedCoordinates : 1; // ================ // 167 bytes per text diff --git a/src/gui/text/qtextcursor.cpp b/src/gui/text/qtextcursor.cpp index c91df3c..d6ac3aa 100644 --- a/src/gui/text/qtextcursor.cpp +++ b/src/gui/text/qtextcursor.cpp @@ -64,7 +64,7 @@ enum { QTextCursorPrivate::QTextCursorPrivate(QTextDocumentPrivate *p) : priv(p), x(0), position(0), anchor(0), adjusted_anchor(0), - currentCharFormat(-1), visualNavigation(false) + currentCharFormat(-1), visualNavigation(false), keepPositionOnInsert(false) { priv->addCursor(this); } @@ -79,6 +79,7 @@ QTextCursorPrivate::QTextCursorPrivate(const QTextCursorPrivate &rhs) x = rhs.x; currentCharFormat = rhs.currentCharFormat; visualNavigation = rhs.visualNavigation; + keepPositionOnInsert = rhs.keepPositionOnInsert; priv->addCursor(this); } @@ -95,7 +96,7 @@ QTextCursorPrivate::AdjustResult QTextCursorPrivate::adjustPosition(int position if (position < positionOfChange || (position == positionOfChange && (op == QTextUndoCommand::KeepCursor - || anchor < position) + || keepPositionOnInsert) ) ) { result = CursorUnchanged; @@ -1276,6 +1277,80 @@ void QTextCursor::setVisualNavigation(bool b) d->visualNavigation = b; } + +/*! + \since 4.7 + + Sets the visual x position for vertical cursor movements. + + The vertical movement x position is cleared automatically when the cursor moves horizontally, and kept + unchanged when the cursor moves vertically. The mechanism allows the cursor to move up and down on a + visually straight line with proportional fonts, and to gently "jump" over short lines. + + A value of -1 indicates no predefined x position. It will then be set automatically the next time the + cursor moves up or down. + + \sa verticalMovementX() + */ +void QTextCursor::setVerticalMovementX(int x) +{ + if (d) + d->x = x; +} + +/*! \since 4.7 + + Returns the visual x position for vertical cursor movements. + + A value of -1 indicates no predefined x position. It will then be set automatically the next time the + cursor moves up or down. + + \sa setVerticalMovementX() + */ +int QTextCursor::verticalMovementX() const +{ + return d ? d->x : -1; +} + +/*! + \since 4.7 + + Returns whether the cursor should keep its current position when text gets inserted at the position of the + cursor. + + The default is false; + + \sa setKeepPositionOnInsert() + */ +bool QTextCursor::keepPositionOnInsert() const +{ + return d ? d->keepPositionOnInsert : false; +} + +/*! + \since 4.7 + + Defines whether the cursor should keep its current position when text gets inserted at the current position of the + cursor. + + If \b is true, the cursor keeps its current position when text gets inserted at the positing of the cursor. + If \b is false, the cursor moves along with the inserted text. + + The default is false. + + Note that a cursor always moves when text is inserted before the current position of the cursor, and it + always keeps its position when text is inserted after the current position of the cursor. + + \sa keepPositionOnInsert() + */ +void QTextCursor::setKeepPositionOnInsert(bool b) +{ + if (d) + d->keepPositionOnInsert = b; +} + + + /*! Inserts \a text at the current position, using the current character format. @@ -1408,16 +1483,16 @@ void QTextCursor::deletePreviousChar() { if (!d || !d->priv) return; - + if (d->position != d->anchor) { removeSelectedText(); return; } - + if (d->anchor < 1 || !d->canDelete(d->anchor-1)) return; d->anchor--; - + QTextDocumentPrivate::FragmentIterator fragIt = d->priv->find(d->anchor); const QTextFragmentData * const frag = fragIt.value(); int fpos = fragIt.position(); @@ -1429,7 +1504,7 @@ void QTextCursor::deletePreviousChar() if (uc.unicode() >= 0xd800 && uc.unicode() < 0xdc00) --d->anchor; } - + d->adjusted_anchor = d->anchor; d->remove(); d->setX(); diff --git a/src/gui/text/qtextcursor.h b/src/gui/text/qtextcursor.h index 3e968a3..251cb33 100644 --- a/src/gui/text/qtextcursor.h +++ b/src/gui/text/qtextcursor.h @@ -132,6 +132,12 @@ public: bool visualNavigation() const; void setVisualNavigation(bool b); + void setVerticalMovementX(int x); + int verticalMovementX() const; + + void setKeepPositionOnInsert(bool b); + bool keepPositionOnInsert() const; + void deleteChar(); void deletePreviousChar(); diff --git a/src/gui/text/qtextcursor_p.h b/src/gui/text/qtextcursor_p.h index 1bdfa78..4e36b95 100644 --- a/src/gui/text/qtextcursor_p.h +++ b/src/gui/text/qtextcursor_p.h @@ -112,7 +112,8 @@ public: int anchor; int adjusted_anchor; int currentCharFormat; - bool visualNavigation; + uint visualNavigation : 1; + uint keepPositionOnInsert : 1; }; QT_END_NAMESPACE diff --git a/src/gui/text/qtextdocumentlayout.cpp b/src/gui/text/qtextdocumentlayout.cpp index f12bf0b..eeb66ce 100644 --- a/src/gui/text/qtextdocumentlayout.cpp +++ b/src/gui/text/qtextdocumentlayout.cpp @@ -79,7 +79,7 @@ Q_GUI_EXPORT extern int qt_defaultDpi(); // ################ should probably add frameFormatChange notification! -struct QLayoutStruct; +struct QTextLayoutStruct; class QTextFrameData : public QTextFrameLayoutData { @@ -109,7 +109,7 @@ public: QFixed minimumWidth; QFixed maximumWidth; - QLayoutStruct *currentLayoutStruct; + QTextLayoutStruct *currentLayoutStruct; bool sizeDirty; bool layoutDirty; @@ -123,8 +123,8 @@ QTextFrameData::QTextFrameData() { } -struct QLayoutStruct { - QLayoutStruct() : maximumWidth(QFIXED_MAX), fullLayout(false) +struct QTextLayoutStruct { + QTextLayoutStruct() : maximumWidth(QFIXED_MAX), fullLayout(false) {} QTextFrame *frame; QFixed x_left; @@ -477,9 +477,9 @@ public: HitPoint hitTest(QTextTable *table, const QFixedPoint &point, int *position, QTextLayout **l, Qt::HitTestAccuracy accuracy) const; HitPoint hitTest(QTextBlock bl, const QFixedPoint &point, int *position, QTextLayout **l, Qt::HitTestAccuracy accuracy) const; - QLayoutStruct layoutCell(QTextTable *t, const QTextTableCell &cell, QFixed width, - int layoutFrom, int layoutTo, QTextTableData *tableData, QFixed absoluteTableY, - bool withPageBreaks); + QTextLayoutStruct layoutCell(QTextTable *t, const QTextTableCell &cell, QFixed width, + int layoutFrom, int layoutTo, QTextTableData *tableData, QFixed absoluteTableY, + bool withPageBreaks); void setCellPosition(QTextTable *t, const QTextTableCell &cell, const QPointF &pos); QRectF layoutTable(QTextTable *t, int layoutFrom, int layoutTo, QFixed parentY); @@ -490,13 +490,13 @@ public: QRectF layoutFrame(QTextFrame *f, int layoutFrom, int layoutTo, QFixed frameWidth, QFixed frameHeight, QFixed parentY = 0); void layoutBlock(const QTextBlock &bl, int blockPosition, const QTextBlockFormat &blockFormat, - QLayoutStruct *layoutStruct, int layoutFrom, int layoutTo, const QTextBlockFormat *previousBlockFormat); - void layoutFlow(QTextFrame::Iterator it, QLayoutStruct *layoutStruct, int layoutFrom, int layoutTo, QFixed width = 0); - void pageBreakInsideTable(QTextTable *table, QLayoutStruct *layoutStruct); + QTextLayoutStruct *layoutStruct, int layoutFrom, int layoutTo, const QTextBlockFormat *previousBlockFormat); + void layoutFlow(QTextFrame::Iterator it, QTextLayoutStruct *layoutStruct, int layoutFrom, int layoutTo, QFixed width = 0); + void pageBreakInsideTable(QTextTable *table, QTextLayoutStruct *layoutStruct); - void floatMargins(const QFixed &y, const QLayoutStruct *layoutStruct, QFixed *left, QFixed *right) const; - QFixed findY(QFixed yFrom, const QLayoutStruct *layoutStruct, QFixed requiredWidth) const; + void floatMargins(const QFixed &y, const QTextLayoutStruct *layoutStruct, QFixed *left, QFixed *right) const; + QFixed findY(QFixed yFrom, const QTextLayoutStruct *layoutStruct, QFixed requiredWidth) const; QVector<QCheckPoint> checkPoints; @@ -1487,12 +1487,12 @@ static QFixed firstChildPos(const QTextFrame *f) return flowPosition(f->begin()); } -QLayoutStruct QTextDocumentLayoutPrivate::layoutCell(QTextTable *t, const QTextTableCell &cell, QFixed width, - int layoutFrom, int layoutTo, QTextTableData *td, - QFixed absoluteTableY, bool withPageBreaks) +QTextLayoutStruct QTextDocumentLayoutPrivate::layoutCell(QTextTable *t, const QTextTableCell &cell, QFixed width, + int layoutFrom, int layoutTo, QTextTableData *td, + QFixed absoluteTableY, bool withPageBreaks) { LDEBUG << "layoutCell"; - QLayoutStruct layoutStruct; + QTextLayoutStruct layoutStruct; layoutStruct.frame = t; layoutStruct.minimumWidth = 0; layoutStruct.maximumWidth = QFIXED_MAX; @@ -1641,9 +1641,9 @@ recalc_minmax_widths: // to figure out the min and the max width lay out the cell at // maximum width. otherwise the maxwidth calculation sometimes // returns wrong values - QLayoutStruct layoutStruct = layoutCell(table, cell, QFIXED_MAX, layoutFrom, - layoutTo, td, absoluteTableY, - /*withPageBreaks =*/false); + QTextLayoutStruct layoutStruct = layoutCell(table, cell, QFIXED_MAX, layoutFrom, + layoutTo, td, absoluteTableY, + /*withPageBreaks =*/false); // distribute the minimum width over all columns the cell spans QFixed widthToDistribute = layoutStruct.minimumWidth + widthPadding; @@ -1868,10 +1868,10 @@ relayout: ++rowCellCount; const QFixed width = td->cellWidth(c, cspan) - widthPadding; - QLayoutStruct layoutStruct = layoutCell(table, cell, width, - layoutFrom, layoutTo, - td, absoluteTableY, - /*withPageBreaks =*/true); + QTextLayoutStruct layoutStruct = layoutCell(table, cell, width, + layoutFrom, layoutTo, + td, absoluteTableY, + /*withPageBreaks =*/true); const QFixed height = layoutStruct.y + bottomPadding + topPadding; @@ -1976,7 +1976,7 @@ void QTextDocumentLayoutPrivate::positionFloat(QTextFrame *frame, QTextLine *cur QTextFrameData *pd = data(parent); Q_ASSERT(pd && pd->currentLayoutStruct); - QLayoutStruct *layoutStruct = pd->currentLayoutStruct; + QTextLayoutStruct *layoutStruct = pd->currentLayoutStruct; if (!pd->floats.contains(frame)) pd->floats.append(frame); @@ -2116,7 +2116,7 @@ QRectF QTextDocumentLayoutPrivate::layoutFrame(QTextFrame *f, int layoutFrom, in // function. fd->contentsWidth = newContentsWidth; - QLayoutStruct layoutStruct; + QTextLayoutStruct layoutStruct; layoutStruct.frame = f; layoutStruct.x_left = fd->leftMargin + fd->border + fd->padding; layoutStruct.x_right = layoutStruct.x_left + newContentsWidth; @@ -2179,7 +2179,7 @@ QRectF QTextDocumentLayoutPrivate::layoutFrame(QTextFrame *f, int layoutFrom, in return layoutStruct.updateRect; } -void QTextDocumentLayoutPrivate::layoutFlow(QTextFrame::Iterator it, QLayoutStruct *layoutStruct, +void QTextDocumentLayoutPrivate::layoutFlow(QTextFrame::Iterator it, QTextLayoutStruct *layoutStruct, int layoutFrom, int layoutTo, QFixed width) { LDEBUG << "layoutFlow from=" << layoutFrom << "to=" << layoutTo; @@ -2509,7 +2509,7 @@ void QTextDocumentLayoutPrivate::layoutFlow(QTextFrame::Iterator it, QLayoutStru } void QTextDocumentLayoutPrivate::layoutBlock(const QTextBlock &bl, int blockPosition, const QTextBlockFormat &blockFormat, - QLayoutStruct *layoutStruct, int layoutFrom, int layoutTo, const QTextBlockFormat *previousBlockFormat) + QTextLayoutStruct *layoutStruct, int layoutFrom, int layoutTo, const QTextBlockFormat *previousBlockFormat) { Q_Q(QTextDocumentLayout); @@ -2718,7 +2718,7 @@ void QTextDocumentLayoutPrivate::layoutBlock(const QTextBlock &bl, int blockPosi } } -void QTextDocumentLayoutPrivate::floatMargins(const QFixed &y, const QLayoutStruct *layoutStruct, +void QTextDocumentLayoutPrivate::floatMargins(const QFixed &y, const QTextLayoutStruct *layoutStruct, QFixed *left, QFixed *right) const { // qDebug() << "floatMargins y=" << y; @@ -2740,7 +2740,7 @@ void QTextDocumentLayoutPrivate::floatMargins(const QFixed &y, const QLayoutStru // qDebug() << "floatMargins: left="<<*left<<"right="<<*right<<"y="<<y; } -QFixed QTextDocumentLayoutPrivate::findY(QFixed yFrom, const QLayoutStruct *layoutStruct, QFixed requiredWidth) const +QFixed QTextDocumentLayoutPrivate::findY(QFixed yFrom, const QTextLayoutStruct *layoutStruct, QFixed requiredWidth) const { QFixed right, left; requiredWidth = qMin(requiredWidth, layoutStruct->x_right - layoutStruct->x_left); diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index 3f67408..f5e252c 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -89,9 +89,9 @@ static QFixed alignLine(QTextEngine *eng, const QScriptLine &line) if (align & Qt::AlignJustify && eng->option.textDirection() == Qt::RightToLeft) align = Qt::AlignRight; if (align & Qt::AlignRight) - x = line.width - (line.textWidth + leadingSpaceWidth(eng, line)); + x = line.width - (line.textAdvance + leadingSpaceWidth(eng, line)); else if (align & Qt::AlignHCenter) - x = (line.width - line.textWidth)/2; + x = (line.width - line.textAdvance)/2; } return x; } diff --git a/src/gui/text/qtextoption.cpp b/src/gui/text/qtextoption.cpp index c1e254c..527b603 100644 --- a/src/gui/text/qtextoption.cpp +++ b/src/gui/text/qtextoption.cpp @@ -145,7 +145,7 @@ QTextOption &QTextOption::operator=(const QTextOption &o) \sa tabArray(), setTabStop(), setTabs() */ -void QTextOption::setTabArray(QList<qreal> tabStops) +void QTextOption::setTabArray(QList<qreal> tabStops) // Qt5: const ref { if (!d) d = new QTextOptionPrivate; @@ -165,7 +165,7 @@ void QTextOption::setTabArray(QList<qreal> tabStops) \sa tabStops() */ -void QTextOption::setTabs(QList<QTextOption::Tab> tabStops) +void QTextOption::setTabs(QList<QTextOption::Tab> tabStops) // Qt5: const ref { if (!d) d = new QTextOptionPrivate; @@ -391,6 +391,12 @@ QList<QTextOption::Tab> QTextOption::tabs() const */ /*! + \fn Tab::Tab(qreal pos, TabType tabType, QChar delim = QChar()) + Creates a tab with the given position, tab type, and (for DelimiterTab) delimiter + \since 4.7 +*/ + +/*! \fn bool Tab::operator==(const Tab &other) const Returns true if tab \a other is equal to this tab; diff --git a/src/gui/text/qtextoption.h b/src/gui/text/qtextoption.h index 1381ed1..5af7834 100644 --- a/src/gui/text/qtextoption.h +++ b/src/gui/text/qtextoption.h @@ -68,6 +68,8 @@ public: struct Q_GUI_EXPORT Tab { inline Tab() : position(80), type(QTextOption::LeftTab) { } + inline Tab(qreal pos, TabType tabType, QChar delim = QChar()) + : position(pos), type(tabType), delimiter(delim) {} inline bool operator==(const Tab &other) const { return type == other.type diff --git a/src/gui/text/text.pri b/src/gui/text/text.pri index 9ec3142..34311a9 100644 --- a/src/gui/text/text.pri +++ b/src/gui/text/text.pri @@ -138,7 +138,8 @@ contains(QT_CONFIG, freetype) { ../3rdparty/freetype/src/base/ftinit.c \ ../3rdparty/freetype/src/base/ftmm.c \ ../3rdparty/freetype/src/base/fttype1.c \ - ../3rdparty/freetype/src/base/ftbitmap.c\ + ../3rdparty/freetype/src/base/ftsynth.c \ + ../3rdparty/freetype/src/base/ftbitmap.c \ ../3rdparty/freetype/src/bdf/bdf.c \ ../3rdparty/freetype/src/cache/ftcache.c \ ../3rdparty/freetype/src/cff/cff.c \ |