From cf5286eca4b8d35ca1f8344ebbdd88c1511705c3 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Fri, 26 Aug 2011 10:20:41 +0200 Subject: QPA event loop: Set a timeout != 0 if there are no timers. Leaving it at 0 leads to event checking with 100% CPU even though we know that there are no events. Acknowledged-by: jlind --- src/gui/kernel/qeventdispatcher_qpa.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/kernel/qeventdispatcher_qpa.cpp b/src/gui/kernel/qeventdispatcher_qpa.cpp index 200696d..3f2e8b2 100644 --- a/src/gui/kernel/qeventdispatcher_qpa.cpp +++ b/src/gui/kernel/qeventdispatcher_qpa.cpp @@ -284,7 +284,7 @@ int QEventDispatcherQPA::select(int nfds, fd_set *readfds, fd_set *writefds, fd_ Q_D(QEventDispatcherQPA); int retVal = 0; if (d->hasIntegration()) { - qint64 timeoutmsec = 0; + qint64 timeoutmsec = 1000; // wait a second if we don't have timers if (timeout) timeoutmsec = timeout->tv_sec * 1000 + (timeout->tv_usec/1000); d->selectReturnMutex->lock(); -- cgit v0.12 From f550d219378e5669601de416254b3585fe3f5708 Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Fri, 2 Sep 2011 13:35:07 +0200 Subject: QGlyphRun: don't detach if the decoration wasn't actually changed Merge-request: 2652 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/gui/text/qglyphrun.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/gui/text/qglyphrun.cpp b/src/gui/text/qglyphrun.cpp index 442f7cc..90790ed 100644 --- a/src/gui/text/qglyphrun.cpp +++ b/src/gui/text/qglyphrun.cpp @@ -294,6 +294,9 @@ bool QGlyphRun::overline() const */ void QGlyphRun::setOverline(bool overline) { + if (d->overline == overline) + return; + detach(); d->overline = overline; } @@ -316,6 +319,9 @@ bool QGlyphRun::underline() const */ void QGlyphRun::setUnderline(bool underline) { + if (d->underline == underline) + return; + detach(); d->underline = underline; } @@ -338,6 +344,9 @@ bool QGlyphRun::strikeOut() const */ void QGlyphRun::setStrikeOut(bool strikeOut) { + if (d->strikeOut == strikeOut) + return; + detach(); d->strikeOut = strikeOut; } -- cgit v0.12 From 145de5acb68f320125b7566a7d726a5a7786a5f8 Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Fri, 2 Sep 2011 13:35:12 +0200 Subject: QGlyphRun: make operator != inlined Merge-request: 2652 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/gui/text/qglyphrun.cpp | 6 ++---- src/gui/text/qglyphrun.h | 4 +++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/gui/text/qglyphrun.cpp b/src/gui/text/qglyphrun.cpp index 90790ed..3633978 100644 --- a/src/gui/text/qglyphrun.cpp +++ b/src/gui/text/qglyphrun.cpp @@ -156,13 +156,11 @@ bool QGlyphRun::operator==(const QGlyphRun &other) const } /*! + \fn bool QGlyphRun::operator!=(const QGlyphRun &other) const + Compares \a other to this QGlyphRun object. Returns true if any of the list of glyph indexes, the list of positions or the font are different, otherwise returns false. */ -bool QGlyphRun::operator!=(const QGlyphRun &other) const -{ - return !(*this == other); -} /*! Returns the font selected for this QGlyphRun object. diff --git a/src/gui/text/qglyphrun.h b/src/gui/text/qglyphrun.h index cf407a8..bc7f4ff 100644 --- a/src/gui/text/qglyphrun.h +++ b/src/gui/text/qglyphrun.h @@ -79,8 +79,10 @@ public: void clear(); QGlyphRun &operator=(const QGlyphRun &other); + bool operator==(const QGlyphRun &other) const; - bool operator!=(const QGlyphRun &other) const; + inline bool operator!=(const QGlyphRun &other) const + { return !operator==(other); } void setOverline(bool overline); bool overline() const; -- cgit v0.12 From 56ef015b1c2384e0590f19e938d349bcffdb6961 Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Fri, 2 Sep 2011 13:35:18 +0200 Subject: optimize QGlyphRun's operator == a bit Merge-request: 2652 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/gui/text/qglyphrun.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/gui/text/qglyphrun.cpp b/src/gui/text/qglyphrun.cpp index 3633978..7f43378 100644 --- a/src/gui/text/qglyphrun.cpp +++ b/src/gui/text/qglyphrun.cpp @@ -140,14 +140,18 @@ bool QGlyphRun::operator==(const QGlyphRun &other) const return false; } - for (int i=0; iglyphIndexDataSize, d->glyphPositionDataSize); ++i) { - if (i < d->glyphIndexDataSize && d->glyphIndexData[i] != other.d->glyphIndexData[i]) - return false; - - if (i < d->glyphPositionDataSize && d->glyphPositionData[i] != other.d->glyphPositionData[i]) - return false; + if (d->glyphIndexData != other.d->glyphIndexData) { + for (int i = 0; i < d->glyphIndexDataSize; ++i) { + if (d->glyphIndexData[i] != other.d->glyphIndexData[i]) + return false; + } + } + if (d->glyphPositionData != other.d->glyphPositionData) { + for (int i = 0; i < d->glyphPositionDataSize; ++i) { + if (d->glyphPositionData[i] != other.d->glyphPositionData[i]) + return false; + } } - return (d->overline == other.d->overline && d->underline == other.d->underline -- cgit v0.12 From 32603c5e40948491f0644d0d17a7e8bbff8d3e0c Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Fri, 2 Sep 2011 13:58:35 +0200 Subject: QRawFont: add missed operator != Merge-request: 1343 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/gui/text/qrawfont.cpp | 6 ++++++ src/gui/text/qrawfont.h | 3 +++ 2 files changed, 9 insertions(+) diff --git a/src/gui/text/qrawfont.cpp b/src/gui/text/qrawfont.cpp index 60a6cb3..9d8c6cc 100644 --- a/src/gui/text/qrawfont.cpp +++ b/src/gui/text/qrawfont.cpp @@ -284,6 +284,12 @@ bool QRawFont::operator==(const QRawFont &other) const } /*! + \fn bool QRawFont::operator!=(const QRawFont &other) const + + Returns true if this QRawFont is not equal to \a other. Otherwise, returns false. +*/ + +/*! Returns the ascent of this QRawFont in pixel units. \sa QFontMetricsF::ascent() diff --git a/src/gui/text/qrawfont.h b/src/gui/text/qrawfont.h index d5b5680..1edbf4a 100644 --- a/src/gui/text/qrawfont.h +++ b/src/gui/text/qrawfont.h @@ -81,7 +81,10 @@ public: bool isValid() const; QRawFont &operator=(const QRawFont &other); + bool operator==(const QRawFont &other) const; + inline bool operator!=(const QRawFont &other) const + { return !operator==(other); } QString familyName() const; QString styleName() const; -- cgit v0.12 From 3926aa4b69caa9037d610b4e212d99dae86d500c Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Fri, 2 Sep 2011 13:58:40 +0200 Subject: fix typo in the docs Merge-request: 1343 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/gui/text/qrawfont.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/text/qrawfont.cpp b/src/gui/text/qrawfont.cpp index 9d8c6cc..2128711 100644 --- a/src/gui/text/qrawfont.cpp +++ b/src/gui/text/qrawfont.cpp @@ -77,7 +77,7 @@ QT_BEGIN_NAMESPACE A QRawFont object represents a single, physical instance of a given font in a given pixel size. I.e. in the typical case it represents a set of TrueType or OpenType font tables and uses a - user specified pixel size to convert metrics into logical pixel units. In can be used in + user specified pixel size to convert metrics into logical pixel units. It can be used in combination with the QGlyphRun class to draw specific glyph indexes at specific positions, and also have accessors to some relevant data in the physical font. -- cgit v0.12 From ab31160c72ea7e7b03604c87ecac11d756da9dce Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Fri, 2 Sep 2011 13:58:46 +0200 Subject: on windows, don't resolve the gdi32's symbols for each QRawFont instance Merge-request: 1343 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/gui/text/qrawfont_p.h | 17 +++------------- src/gui/text/qrawfont_win.cpp | 46 +++++++++++++++++++++---------------------- 2 files changed, 26 insertions(+), 37 deletions(-) diff --git a/src/gui/text/qrawfont_p.h b/src/gui/text/qrawfont_p.h index fdf7cad..84e83cf 100644 --- a/src/gui/text/qrawfont_p.h +++ b/src/gui/text/qrawfont_p.h @@ -71,21 +71,17 @@ public: , thread(0) #if defined(Q_WS_WIN) , fontHandle(NULL) - , ptrAddFontMemResourceEx(NULL) - , ptrRemoveFontMemResourceEx(NULL) #endif {} QRawFontPrivate(const QRawFontPrivate &other) - : hintingPreference(other.hintingPreference) + : fontEngine(other.fontEngine) + , hintingPreference(other.hintingPreference) , thread(other.thread) #if defined(Q_WS_WIN) , fontHandle(NULL) - , ptrAddFontMemResourceEx(other.ptrAddFontMemResourceEx) - , ptrRemoveFontMemResourceEx(other.ptrRemoveFontMemResourceEx) #endif { - fontEngine = other.fontEngine; if (fontEngine != 0) fontEngine->ref.ref(); } @@ -111,14 +107,7 @@ public: #if defined(Q_WS_WIN) HANDLE fontHandle; - - typedef HANDLE (WINAPI *PtrAddFontMemResourceEx)(PVOID, DWORD, PVOID, DWORD *); - typedef BOOL (WINAPI *PtrRemoveFontMemResourceEx)(HANDLE); - - PtrAddFontMemResourceEx ptrAddFontMemResourceEx; - PtrRemoveFontMemResourceEx ptrRemoveFontMemResourceEx; - -#endif // Q_WS_WIN +#endif }; QT_END_NAMESPACE diff --git a/src/gui/text/qrawfont_win.cpp b/src/gui/text/qrawfont_win.cpp index 779652f..f612ef1 100644 --- a/src/gui/text/qrawfont_win.cpp +++ b/src/gui/text/qrawfont_win.cpp @@ -525,22 +525,31 @@ extern QFontEngine *qt_load_font_engine_win(const QFontDef &request); // From qfontdatabase.cpp extern QFont::Weight weightFromInteger(int weight); -void QRawFontPrivate::platformCleanUp() +typedef HANDLE (WINAPI *PtrAddFontMemResourceEx)(PVOID, DWORD, PVOID, DWORD *); +static PtrAddFontMemResourceEx ptrAddFontMemResourceEx = 0; +typedef BOOL (WINAPI *PtrRemoveFontMemResourceEx)(HANDLE); +static PtrRemoveFontMemResourceEx ptrRemoveFontMemResourceEx = 0; + +static void resolveGdi32() { - if (fontHandle != NULL) { - if (ptrRemoveFontMemResourceEx == NULL) { - void *func = QSystemLibrary::resolve(QLatin1String("gdi32"), "RemoveFontMemResourceEx"); - ptrRemoveFontMemResourceEx = - reinterpret_cast(func); + static bool triedResolve = false; + if (!triedResolve) { + QSystemLibrary gdi32(QLatin1String("gdi32")); + if (gdi32.load()) { + ptrAddFontMemResourceEx = (PtrAddFontMemResourceEx)gdi32.resolve("AddFontMemResourceEx"); + ptrRemoveFontMemResourceEx = (PtrRemoveFontMemResourceEx)gdi32.resolve("RemoveFontMemResourceEx"); } - if (ptrRemoveFontMemResourceEx == NULL) { - qWarning("QRawFont::platformCleanUp: Can't find RemoveFontMemResourceEx in gdi32"); - fontHandle = NULL; - } else { + triedResolve = true; + } +} + +void QRawFontPrivate::platformCleanUp() +{ + if (fontHandle != NULL) { + if (ptrRemoveFontMemResourceEx) ptrRemoveFontMemResourceEx(fontHandle); - fontHandle = NULL; - } + fontHandle = NULL; } } @@ -571,18 +580,9 @@ void QRawFontPrivate::platformLoadFromData(const QByteArray &_fontData, return; } - if (ptrAddFontMemResourceEx == NULL || ptrRemoveFontMemResourceEx == NULL) { - void *func = QSystemLibrary::resolve(QLatin1String("gdi32"), "RemoveFontMemResourceEx"); - ptrRemoveFontMemResourceEx = - reinterpret_cast(func); - - func = QSystemLibrary::resolve(QLatin1String("gdi32"), "AddFontMemResourceEx"); - ptrAddFontMemResourceEx = - reinterpret_cast(func); - } - Q_ASSERT(fontHandle == NULL); - if (ptrAddFontMemResourceEx != NULL && ptrRemoveFontMemResourceEx != NULL) { + resolveGdi32(); + if (ptrAddFontMemResourceEx && ptrRemoveFontMemResourceEx) { DWORD count = 0; fontData = font.data(); fontHandle = ptrAddFontMemResourceEx(fontData.data(), fontData.size(), 0, &count); -- cgit v0.12 From 106a896b2e9326b25a704ed683bca5ee739e7c78 Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Fri, 2 Sep 2011 13:58:51 +0200 Subject: fix "comparison between signed and unsigned" warnings Merge-request: 1343 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/gui/text/qrawfont_win.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/gui/text/qrawfont_win.cpp b/src/gui/text/qrawfont_win.cpp index f612ef1..4d2305f 100644 --- a/src/gui/text/qrawfont_win.cpp +++ b/src/gui/text/qrawfont_win.cpp @@ -61,18 +61,16 @@ namespace { operator T() const { T littleEndian = 0; - for (int i=0; i &operator=(const T &t) { - for (int i=0; i> (sizeof(T) - i - 1) * 8) & 0xff); - } return *this; } @@ -214,9 +212,9 @@ namespace { + nameRecord->offset; const BigEndian *s = reinterpret_cast *>(ptr); - for (int j=0; jlength / sizeof(quint16); ++j) - name += QChar(s[j]); - + const BigEndian *e = s + nameRecord->length / sizeof(quint16); + while (s != e) + name += QChar(*s++); break; } } -- cgit v0.12 From 4d8cd11179e6cca162efe650d308124dc7aefb14 Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Fri, 2 Sep 2011 13:58:57 +0200 Subject: micro optimizations use an inlined version of isValid() everywhere; don't detach where is non required; get rid of extra checks where possible Merge-request: 1343 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/gui/text/qrawfont.cpp | 124 +++++++++++------------------------------- src/gui/text/qrawfont.h | 3 - src/gui/text/qrawfont_p.h | 8 +++ src/gui/text/qrawfont_win.cpp | 22 +++----- 4 files changed, 48 insertions(+), 109 deletions(-) diff --git a/src/gui/text/qrawfont.cpp b/src/gui/text/qrawfont.cpp index 2128711..c477a6a 100644 --- a/src/gui/text/qrawfont.cpp +++ b/src/gui/text/qrawfont.cpp @@ -46,7 +46,6 @@ #include "qrawfont.h" #include "qrawfont_p.h" -#include #include QT_BEGIN_NAMESPACE @@ -190,8 +189,7 @@ QRawFont &QRawFont::operator=(const QRawFont &other) */ bool QRawFont::isValid() const { - Q_ASSERT(d->thread == 0 || d->thread == QThread::currentThread()); - return d->fontEngine != 0; + return d->isValid(); } /*! @@ -225,7 +223,7 @@ void QRawFont::loadFromData(const QByteArray &fontData, qreal pixelSize, QFont::HintingPreference hintingPreference) { - detach(); + d.detach(); d->cleanUp(); d->hintingPreference = hintingPreference; d->thread = QThread::currentThread(); @@ -247,13 +245,13 @@ void QRawFont::loadFromData(const QByteArray &fontData, QImage QRawFont::alphaMapForGlyph(quint32 glyphIndex, AntialiasingType antialiasingType, const QTransform &transform) const { - if (!isValid()) + if (!d->isValid()) return QImage(); if (antialiasingType == SubPixelAntialiasing) return d->fontEngine->alphaRGBMapForGlyph(glyphIndex, QFixed(), 0, transform); - else - return d->fontEngine->alphaMapForGlyph(glyphIndex, QFixed(), transform); + + return d->fontEngine->alphaMapForGlyph(glyphIndex, QFixed(), transform); } /*! @@ -266,7 +264,7 @@ QImage QRawFont::alphaMapForGlyph(quint32 glyphIndex, AntialiasingType antialias */ QPainterPath QRawFont::pathForGlyph(quint32 glyphIndex) const { - if (!isValid()) + if (!d->isValid()) return QPainterPath(); QFixedPoint position; @@ -296,10 +294,7 @@ bool QRawFont::operator==(const QRawFont &other) const */ qreal QRawFont::ascent() const { - if (!isValid()) - return 0.0; - - return d->fontEngine->ascent().toReal(); + return d->isValid() ? d->fontEngine->ascent().toReal() : 0.0; } /*! @@ -309,10 +304,7 @@ qreal QRawFont::ascent() const */ qreal QRawFont::descent() const { - if (!isValid()) - return 0.0; - - return d->fontEngine->descent().toReal(); + return d->isValid() ? d->fontEngine->descent().toReal() : 0.0; } /*! @@ -322,10 +314,7 @@ qreal QRawFont::descent() const */ qreal QRawFont::xHeight() const { - if (!isValid()) - return 0.0; - - return d->fontEngine->xHeight().toReal(); + return d->isValid() ? d->fontEngine->xHeight().toReal() : 0.0; } /*! @@ -335,10 +324,7 @@ qreal QRawFont::xHeight() const */ qreal QRawFont::leading() const { - if (!isValid()) - return 0.0; - - return d->fontEngine->leading().toReal(); + return d->isValid() ? d->fontEngine->leading().toReal() : 0.0; } /*! @@ -348,10 +334,7 @@ qreal QRawFont::leading() const */ qreal QRawFont::averageCharWidth() const { - if (!isValid()) - return 0.0; - - return d->fontEngine->averageCharWidth().toReal(); + return d->isValid() ? d->fontEngine->averageCharWidth().toReal() : 0.0; } /*! @@ -361,10 +344,7 @@ qreal QRawFont::averageCharWidth() const */ qreal QRawFont::maxCharWidth() const { - if (!isValid()) - return 0.0; - - return d->fontEngine->maxCharWidth(); + return d->isValid() ? d->fontEngine->maxCharWidth() : 0.0; } /*! @@ -376,10 +356,7 @@ qreal QRawFont::maxCharWidth() const */ qreal QRawFont::pixelSize() const { - if (!isValid()) - return 0.0; - - return d->fontEngine->fontDef.pixelSize; + return d->isValid() ? d->fontEngine->fontDef.pixelSize : 0.0; } /*! @@ -392,10 +369,7 @@ qreal QRawFont::pixelSize() const */ qreal QRawFont::unitsPerEm() const { - if (!isValid()) - return 0.0; - - return d->fontEngine->emSquareSize().toReal(); + return d->isValid() ? d->fontEngine->emSquareSize().toReal() : 0.0; } /*! @@ -403,10 +377,7 @@ qreal QRawFont::unitsPerEm() const */ QString QRawFont::familyName() const { - if (!isValid()) - return QString(); - - return d->fontEngine->fontDef.family; + return d->isValid() ? d->fontEngine->fontDef.family : QString(); } /*! @@ -416,10 +387,7 @@ QString QRawFont::familyName() const */ QString QRawFont::styleName() const { - if (!isValid()) - return QString(); - - return d->fontEngine->fontDef.styleName; + return d->isValid() ? d->fontEngine->fontDef.styleName : QString(); } /*! @@ -429,10 +397,7 @@ QString QRawFont::styleName() const */ QFont::Style QRawFont::style() const { - if (!isValid()) - return QFont::StyleNormal; - - return QFont::Style(d->fontEngine->fontDef.style); + return d->isValid() ? QFont::Style(d->fontEngine->fontDef.style) : QFont::StyleNormal; } /*! @@ -442,10 +407,7 @@ QFont::Style QRawFont::style() const */ int QRawFont::weight() const { - if (!isValid()) - return -1; - - return int(d->fontEngine->fontDef.weight); + return d->isValid() ? int(d->fontEngine->fontDef.weight) : -1; } /*! @@ -463,7 +425,7 @@ int QRawFont::weight() const */ QVector QRawFont::glyphIndexesForString(const QString &text) const { - if (!isValid()) + if (!d->isValid()) return QVector(); int nglyphs = text.size(); @@ -496,7 +458,7 @@ QVector QRawFont::glyphIndexesForString(const QString &text) const */ bool QRawFont::glyphIndexesForChars(const QChar *chars, int numChars, quint32 *glyphIndexes, int *numGlyphs) const { - if (!isValid()) + if (!d->isValid()) return false; QGlyphLayout glyphs; @@ -513,7 +475,7 @@ bool QRawFont::glyphIndexesForChars(const QChar *chars, int numChars, quint32 *g */ QVector QRawFont::advancesForGlyphIndexes(const QVector &glyphIndexes) const { - if (!isValid()) + if (!d->isValid()) return QVector(); int numGlyphs = glyphIndexes.size(); @@ -540,7 +502,7 @@ QVector QRawFont::advancesForGlyphIndexes(const QVector &glyph */ bool QRawFont::advancesForGlyphIndexes(const quint32 *glyphIndexes, QPointF *advances, int numGlyphs) const { - if (!isValid()) + if (!d->isValid()) return false; QGlyphLayout glyphs; @@ -566,10 +528,7 @@ bool QRawFont::advancesForGlyphIndexes(const quint32 *glyphIndexes, QPointF *adv */ QFont::HintingPreference QRawFont::hintingPreference() const { - if (!isValid()) - return QFont::PreferDefaultHinting; - - return d->hintingPreference; + return d->isValid() ? d->hintingPreference : QFont::PreferDefaultHinting; } /*! @@ -580,7 +539,7 @@ QFont::HintingPreference QRawFont::hintingPreference() const */ QByteArray QRawFont::fontTable(const char *tagName) const { - if (!isValid()) + if (!d->isValid()) return QByteArray(); const quint32 *tagId = reinterpret_cast(tagName); @@ -603,9 +562,9 @@ extern QList qt_determine_writing_systems_from_tru */ QList QRawFont::supportedWritingSystems() const { - if (isValid()) { + if (d->isValid()) { QByteArray os2Table = fontTable("OS/2"); - if (!os2Table.isEmpty() && os2Table.size() > 86) { + if (os2Table.size() > 86) { char *data = os2Table.data(); quint32 *bigEndianUnicodeRanges = reinterpret_cast(data + 42); quint32 *bigEndianCodepageRanges = reinterpret_cast(data + 78); @@ -633,10 +592,7 @@ QList QRawFont::supportedWritingSystems() const */ bool QRawFont::supportsCharacter(QChar character) const { - if (!isValid()) - return false; - - return d->fontEngine->canRender(&character, 1); + return d->isValid() && d->fontEngine->canRender(&character, 1); } /*! @@ -647,9 +603,6 @@ bool QRawFont::supportsCharacter(QChar character) const */ bool QRawFont::supportsCharacter(quint32 ucs4) const { - if (!isValid()) - return false; - QChar str[2]; int len; if (!QChar::requiresSurrogates(ucs4)) { @@ -661,7 +614,7 @@ bool QRawFont::supportsCharacter(quint32 ucs4) const len = 2; } - return d->fontEngine->canRender(str, len); + return d->isValid() && d->fontEngine->canRender(str, len); } // qfontdatabase.cpp @@ -673,6 +626,7 @@ extern int qt_script_for_writing_system(QFontDatabase::WritingSystem writingSyst */ QRawFont QRawFont::fromFont(const QFont &font, QFontDatabase::WritingSystem writingSystem) { + QRawFont rawFont; #if defined(Q_WS_MAC) QTextLayout layout(QFontDatabase::writingSystemSample(writingSystem), font); layout.beginLayout(); @@ -683,14 +637,12 @@ QRawFont QRawFont::fromFont(const QFont &font, QFontDatabase::WritingSystem writ // Pick the one matches the family name we originally requested, // if none of them match, just pick the first one for (int i = 0; i < list.size(); i++) { - QGlyphRun glyphs = list.at(i); - QRawFont rawfont = glyphs.rawFont(); + rawfont = list.at(i).rawFont(); if (rawfont.familyName() == font.family()) return rawfont; } return list.at(0).rawFont(); } - return QRawFont(); #else QFontPrivate *font_d = QFontPrivate::get(font); int script = qt_script_for_writing_system(writingSystem); @@ -706,15 +658,12 @@ QRawFont QRawFont::fromFont(const QFont &font, QFontDatabase::WritingSystem writ } if (fe != 0) { - QRawFont rawFont; rawFont.d.data()->fontEngine = fe; rawFont.d.data()->fontEngine->ref.ref(); rawFont.d.data()->hintingPreference = font.hintingPreference(); - return rawFont; - } else { - return QRawFont(); } #endif + return rawFont; } /*! @@ -725,7 +674,7 @@ void QRawFont::setPixelSize(qreal pixelSize) if (d->fontEngine == 0) return; - detach(); + d.detach(); QFontEngine *oldFontEngine = d->fontEngine; d->fontEngine = d->fontEngine->cloneWithSize(pixelSize); @@ -740,15 +689,6 @@ void QRawFont::setPixelSize(qreal pixelSize) /*! \internal */ -void QRawFont::detach() -{ - if (d->ref != 1) - d.detach(); -} - -/*! - \internal -*/ void QRawFontPrivate::cleanUp() { platformCleanUp(); diff --git a/src/gui/text/qrawfont.h b/src/gui/text/qrawfont.h index 1edbf4a..cf77996 100644 --- a/src/gui/text/qrawfont.h +++ b/src/gui/text/qrawfont.h @@ -135,9 +135,6 @@ public: private: friend class QRawFontPrivate; - - void detach(); - QExplicitlySharedDataPointer d; }; diff --git a/src/gui/text/qrawfont_p.h b/src/gui/text/qrawfont_p.h index 84e83cf..3557751 100644 --- a/src/gui/text/qrawfont_p.h +++ b/src/gui/text/qrawfont_p.h @@ -54,7 +54,9 @@ // #include "qrawfont.h" + #include "qfontengine_p.h" +#include #include #if !defined(QT_NO_RAWFONT) @@ -92,6 +94,12 @@ public: cleanUp(); } + inline bool isValid() const + { + Q_ASSERT(thread == 0 || thread == QThread::currentThread()); + return fontEngine != 0; + } + void cleanUp(); void platformCleanUp(); void platformLoadFromData(const QByteArray &fontData, diff --git a/src/gui/text/qrawfont_win.cpp b/src/gui/text/qrawfont_win.cpp index 4d2305f..ea1e75b 100644 --- a/src/gui/text/qrawfont_win.cpp +++ b/src/gui/text/qrawfont_win.cpp @@ -40,6 +40,9 @@ ****************************************************************************/ #include "qrawfont_p.h" + +#if !defined(QT_NO_RAWFONT) + #include #if !defined(QT_NO_DIRECTWRITE) @@ -47,8 +50,6 @@ # include #endif -#if !defined(QT_NO_RAWFONT) - QT_BEGIN_NAMESPACE namespace { @@ -155,7 +156,7 @@ namespace { class EmbeddedFont { public: - EmbeddedFont(const QByteArray &fontData); + EmbeddedFont(const QByteArray &fontData) : m_fontData(fontData) {} QString changeFamilyName(const QString &newFamilyName); QByteArray data() const { return m_fontData; } @@ -166,10 +167,6 @@ namespace { QByteArray m_fontData; }; - EmbeddedFont::EmbeddedFont(const QByteArray &fontData) : m_fontData(fontData) - { - } - TableDirectory *EmbeddedFont::tableDirectoryEntry(const QByteArray &tagName) { Q_ASSERT(tagName.size() == 4); @@ -551,22 +548,21 @@ void QRawFontPrivate::platformCleanUp() } } -void QRawFontPrivate::platformLoadFromData(const QByteArray &_fontData, +void QRawFontPrivate::platformLoadFromData(const QByteArray &fontData, qreal pixelSize, QFont::HintingPreference hintingPreference) { - QByteArray fontData(_fontData); EmbeddedFont font(fontData); #if !defined(QT_NO_DIRECTWRITE) if (hintingPreference == QFont::PreferDefaultHinting - || hintingPreference == QFont::PreferFullHinting) + || hintingPreference == QFont::PreferFullHinting) #endif { GUID guid; CoCreateGuid(&guid); - QString uniqueFamilyName = QString::fromLatin1("f") + QString uniqueFamilyName = QLatin1Char('f') + QString::number(guid.Data1, 36) + QLatin1Char('-') + QString::number(guid.Data2, 36) + QLatin1Char('-') + QString::number(guid.Data3, 36) + QLatin1Char('-') @@ -582,9 +578,7 @@ void QRawFontPrivate::platformLoadFromData(const QByteArray &_fontData, resolveGdi32(); if (ptrAddFontMemResourceEx && ptrRemoveFontMemResourceEx) { DWORD count = 0; - fontData = font.data(); - fontHandle = ptrAddFontMemResourceEx(fontData.data(), fontData.size(), 0, &count); - + fontHandle = ptrAddFontMemResourceEx((void *)fontData.constData(), fontData.size(), 0, &count); if (count == 0 && fontHandle != NULL) { ptrRemoveFontMemResourceEx(fontHandle); fontHandle = NULL; -- cgit v0.12 From 4cc331dc1713758d41f6ddf4b1dd2ed5acb8347f Mon Sep 17 00:00:00 2001 From: luohua Date: Fri, 2 Sep 2011 16:47:56 +0200 Subject: Fixed compiling error in qvfb. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Merge-request: 1324 Reviewed-by: Samuel Rødal --- tools/qvfb/qvfb.pro | 10 ++++++++-- tools/qvfb/qvfbshmem.cpp | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/tools/qvfb/qvfb.pro b/tools/qvfb/qvfb.pro index 29ce202..b5645a3 100644 --- a/tools/qvfb/qvfb.pro +++ b/tools/qvfb/qvfb.pro @@ -16,7 +16,10 @@ HEADERS = qvfb.h \ gammaview.h \ qvfbprotocol.h \ qvfbshmem.h \ - qvfbmmap.h + qvfbmmap.h \ + ../../src/gui/embedded/qlock_p.h \ + ../../src/gui/embedded/qwslock_p.h \ + ../../src/gui/embedded/qwssignalhandler_p.h SOURCES = qvfb.cpp \ qvfbview.cpp \ @@ -25,7 +28,10 @@ SOURCES = qvfb.cpp \ qanimationwriter.cpp \ qvfbprotocol.cpp \ qvfbshmem.cpp \ - qvfbmmap.cpp + qvfbmmap.cpp \ + ../../src/gui/embedded/qlock.cpp \ + ../../src/gui/embedded/qwslock.cpp \ + ../../src/gui/embedded/qwssignalhandler.cpp include(../shared/deviceskin/deviceskin.pri) diff --git a/tools/qvfb/qvfbshmem.cpp b/tools/qvfb/qvfbshmem.cpp index c17a680..5a9aa7c 100644 --- a/tools/qvfb/qvfbshmem.cpp +++ b/tools/qvfb/qvfbshmem.cpp @@ -39,6 +39,7 @@ ** ****************************************************************************/ +#include "qplatformdefs.h" #include "qvfbshmem.h" #include #include -- cgit v0.12 From 82286c2b96d9408b825c9c1d94ad45af371f09ea Mon Sep 17 00:00:00 2001 From: aavit Date: Wed, 7 Sep 2011 08:34:23 +0200 Subject: Make it compile on mac --- src/gui/text/qrawfont.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gui/text/qrawfont.cpp b/src/gui/text/qrawfont.cpp index c477a6a..61bc63e 100644 --- a/src/gui/text/qrawfont.cpp +++ b/src/gui/text/qrawfont.cpp @@ -637,9 +637,9 @@ QRawFont QRawFont::fromFont(const QFont &font, QFontDatabase::WritingSystem writ // Pick the one matches the family name we originally requested, // if none of them match, just pick the first one for (int i = 0; i < list.size(); i++) { - rawfont = list.at(i).rawFont(); - if (rawfont.familyName() == font.family()) - return rawfont; + rawFont = list.at(i).rawFont(); + if (rawFont.familyName() == font.family()) + return rawFont; } return list.at(0).rawFont(); } -- cgit v0.12 From 6f59466721d1d11d11da2c46f9e4092f65b14acf Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Thu, 8 Sep 2011 09:01:43 +0200 Subject: Fix regression in tst_qrawfont Change 4d8cd11179e6cca162efe650d308124dc7aefb14 broke QRawFont on Windows by removing some code. After the font has been renamed, we need to use the new font tables rather than the old ones for registering the font in the system. Reviewed-by: aavit --- src/gui/text/qrawfont_win.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gui/text/qrawfont_win.cpp b/src/gui/text/qrawfont_win.cpp index ea1e75b..a729e31 100644 --- a/src/gui/text/qrawfont_win.cpp +++ b/src/gui/text/qrawfont_win.cpp @@ -578,7 +578,9 @@ void QRawFontPrivate::platformLoadFromData(const QByteArray &fontData, resolveGdi32(); if (ptrAddFontMemResourceEx && ptrRemoveFontMemResourceEx) { DWORD count = 0; - fontHandle = ptrAddFontMemResourceEx((void *)fontData.constData(), fontData.size(), 0, &count); + QByteArray newFontData = font.data(); + fontHandle = ptrAddFontMemResourceEx((void *)newFontData.constData(), newFontData.size(), + 0, &count); if (count == 0 && fontHandle != NULL) { ptrRemoveFontMemResourceEx(fontHandle); fontHandle = NULL; -- cgit v0.12 From 6326227674efa85c1a5320141041110d211efc75 Mon Sep 17 00:00:00 2001 From: John Tapsell Date: Thu, 8 Sep 2011 10:14:33 +0200 Subject: Fix RTL layout for fonts when non-printable character has an advance If a non-printable character has an advance, we would lay out the text as if the character was part of the output, and then ignore the character later when the text was rendered. To fix cases such as this, we take the dontPrint attribute into consideration when adjusting the advances. Task-number: QTBUG-21347 Reviewed-by: Eskil Reviewed-by: Lars --- src/gui/text/qfontengine.cpp | 2 ++ src/gui/text/qtextengine.cpp | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/gui/text/qfontengine.cpp b/src/gui/text/qfontengine.cpp index dec0982..7056861 100644 --- a/src/gui/text/qfontengine.cpp +++ b/src/gui/text/qfontengine.cpp @@ -280,6 +280,8 @@ void QFontEngine::getGlyphPositions(const QGlyphLayout &glyphs, const QTransform int i = glyphs.numGlyphs; int totalKashidas = 0; while(i--) { + if (glyphs.attributes[i].dontPrint) + continue; xpos += glyphs.advances_x[i] + QFixed::fromFixed(glyphs.justifications[i].space_18d6); ypos += glyphs.advances_y[i]; totalKashidas += glyphs.justifications[i].nKashidas; diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp index aa4a20d..6f07131 100644 --- a/src/gui/text/qtextengine.cpp +++ b/src/gui/text/qtextengine.cpp @@ -968,7 +968,7 @@ void QTextEngine::shapeText(int item) const } for (int i = 0; i < si.num_glyphs; ++i) - si.width += glyphs.advances_x[i]; + si.width += glyphs.advances_x[i] * !glyphs.attributes[i].dontPrint; } static inline bool hasCaseChange(const QScriptItem &si) @@ -2658,7 +2658,7 @@ void QTextEngine::splitItem(int item, int pos) const QFixed w = 0; const QGlyphLayout g = shapedGlyphs(&oldItem); for(int j = 0; j < breakGlyph; ++j) - w += g.advances_x[j]; + w += g.advances_x[j] * !g.attributes[j].dontPrint; newItem.width = oldItem.width - w; oldItem.width = w; -- cgit v0.12 From 80294c375eca9687d1c34e9ab048294373e7f00c Mon Sep 17 00:00:00 2001 From: Jiang Jiang Date: Thu, 8 Sep 2011 16:31:53 +0200 Subject: Fix trailing spaces problem by not adding it to QScriptLine.length It seems to be the only sane way to fix it. Previous attempts to fix it by compensating the trailing space width all failed in some cases, one of the trickiest is when we are having embedded LTR text that has trailing spaces in a RTL paragraph. In this patch we leave line.length not including the trailing space length, but saving it to a separated variable, so that we can always add it back when needed (QTextLine::textLength() for instance). It fixed all the problems in different alignments of both RTL and LTR text. And no regression is found yet. Reviewed-by: Eskil --- src/gui/text/qtextengine.cpp | 2 +- src/gui/text/qtextengine_p.h | 3 ++- src/gui/text/qtextlayout.cpp | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp index 6f07131..a0e1751 100644 --- a/src/gui/text/qtextengine.cpp +++ b/src/gui/text/qtextengine.cpp @@ -2951,7 +2951,7 @@ int QTextEngine::lineNumberForTextPosition(int pos) return lines.size() - 1; for (int i = 0; i < lines.size(); ++i) { const QScriptLine& line = lines[i]; - if (line.from + line.length > pos) + if (line.from + line.length + line.trailingSpaces > pos) return i; } return -1; diff --git a/src/gui/text/qtextengine_p.h b/src/gui/text/qtextengine_p.h index b1bd0c3..0a86886 100644 --- a/src/gui/text/qtextengine_p.h +++ b/src/gui/text/qtextengine_p.h @@ -376,7 +376,7 @@ struct Q_AUTOTEST_EXPORT QScriptLine { // created and filled in QTextLine::layout_helper QScriptLine() - : from(0), length(0), + : from(0), trailingSpaces(0), length(0), justified(0), gridfitted(0), hasTrailingSpaces(0), leadingIncluded(0) {} QFixed descent; @@ -388,6 +388,7 @@ struct Q_AUTOTEST_EXPORT QScriptLine QFixed textWidth; QFixed textAdvance; int from; + unsigned short trailingSpaces; signed int length : 28; mutable uint justified : 1; mutable uint gridfitted : 1; diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index 4fd6ddf..cf361a0 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -814,7 +814,7 @@ QTextLine QTextLayout::createLine() if (l && d->lines.at(l-1).length < 0) { QTextLine(l-1, d).setNumColumns(INT_MAX); } - int from = l > 0 ? d->lines.at(l-1).from + d->lines.at(l-1).length : 0; + int from = l > 0 ? d->lines.at(l-1).from + d->lines.at(l-1).length + d->lines.at(l-1).trailingSpaces : 0; int strlen = d->layoutData->string.length(); if (l && from >= strlen) { if (!d->lines.at(l-1).length || d->layoutData->string.at(strlen - 1) != QChar::LineSeparator) @@ -1931,7 +1931,7 @@ found: if (eng->option.flags() & QTextOption::IncludeTrailingSpaces) line.textWidth += lbh.spaceData.textWidth; if (lbh.spaceData.length) { - line.length += lbh.spaceData.length; + line.trailingSpaces = lbh.spaceData.length; line.hasTrailingSpaces = true; } @@ -1995,7 +1995,7 @@ int QTextLine::textLength() const && eng->block.isValid() && i == eng->lines.count()-1) { return eng->lines[i].length - 1; } - return eng->lines[i].length; + return eng->lines[i].length + eng->lines[i].trailingSpaces; } static void drawMenuText(QPainter *p, QFixed x, QFixed y, const QScriptItem &si, QTextItemInt &gf, QTextEngine *eng, -- cgit v0.12 From 786b85b13bc884a8b7eab59c43d6c393863fc470 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Thu, 8 Sep 2011 13:10:47 +0200 Subject: Allocate 16-byte aligned memory independent of platform for raster pool. Fixes crash on MIPS (see original merge request https://qt.gitorious.org/qt/qt/merge_requests/1366). Reviewed-by: Olivier Goffart --- src/gui/painting/qpaintengine_raster.cpp | 54 ++++++++++---------------------- 1 file changed, 17 insertions(+), 37 deletions(-) diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp index 36786c4..bcc5f9d 100644 --- a/src/gui/painting/qpaintengine_raster.cpp +++ b/src/gui/painting/qpaintengine_raster.cpp @@ -3764,6 +3764,11 @@ extern "C" { int q_gray_rendered_spans(QT_FT_Raster raster); } +static inline uchar *alignAddress(uchar *address, quintptr alignmentMask) +{ + return (uchar *)(((quintptr)address + alignmentMask) & ~alignmentMask); +} + void QRasterPaintEnginePrivate::rasterize(QT_FT_Outline *outline, ProcessSpans callback, void *userData, QRasterBuffer *) @@ -3791,19 +3796,10 @@ void QRasterPaintEnginePrivate::rasterize(QT_FT_Outline *outline, // minimize memory reallocations. However if initial size for // raster pool is changed for lower value, reallocations will // occur normally. - const int rasterPoolInitialSize = MINIMUM_POOL_SIZE; - int rasterPoolSize = rasterPoolInitialSize; - unsigned char *rasterPoolBase; -#if defined(Q_WS_WIN64) - rasterPoolBase = - // We make use of setjmp and longjmp in qgrayraster.c which requires - // 16-byte alignment, hence we hardcode this requirement here.. - (unsigned char *) _aligned_malloc(rasterPoolSize, sizeof(void*) * 2); -#else - unsigned char rasterPoolOnStack[rasterPoolInitialSize]; - rasterPoolBase = rasterPoolOnStack; -#endif - Q_CHECK_PTR(rasterPoolBase); + int rasterPoolSize = MINIMUM_POOL_SIZE; + uchar rasterPoolOnStack[MINIMUM_POOL_SIZE + 0xf]; + uchar *rasterPoolBase = alignAddress(rasterPoolOnStack, 0xf); + uchar *rasterPoolOnHeap = 0; qt_ft_grays_raster.raster_reset(*grayRaster.data(), rasterPoolBase, rasterPoolSize); @@ -3839,31 +3835,20 @@ void QRasterPaintEnginePrivate::rasterize(QT_FT_Outline *outline, // Out of memory, reallocate some more and try again... if (error == -6) { // ErrRaster_OutOfMemory from qgrayraster.c - int new_size = rasterPoolSize * 2; - if (new_size > 1024 * 1024) { + rasterPoolSize *= 2; + if (rasterPoolSize > 1024 * 1024) { qWarning("QPainter: Rasterization of primitive failed"); break; } rendered_spans += q_gray_rendered_spans(*grayRaster.data()); -#if defined(Q_WS_WIN64) - _aligned_free(rasterPoolBase); -#else - if (rasterPoolBase != rasterPoolOnStack) // initially on the stack - free(rasterPoolBase); -#endif + free(rasterPoolOnHeap); + rasterPoolOnHeap = (uchar *)malloc(rasterPoolSize + 0xf); - rasterPoolSize = new_size; - rasterPoolBase = -#if defined(Q_WS_WIN64) - // We make use of setjmp and longjmp in qgrayraster.c which requires - // 16-byte alignment, hence we hardcode this requirement here.. - (unsigned char *) _aligned_malloc(rasterPoolSize, sizeof(void*) * 2); -#else - (unsigned char *) malloc(rasterPoolSize); -#endif - Q_CHECK_PTR(rasterPoolBase); // note: we just freed the old rasterPoolBase. I hope it's not fatal. + Q_CHECK_PTR(rasterPoolOnHeap); // note: we just freed the old rasterPoolBase. I hope it's not fatal. + + rasterPoolBase = alignAddress(rasterPoolOnHeap, 0xf); qt_ft_grays_raster.raster_done(*grayRaster.data()); qt_ft_grays_raster.raster_new(grayRaster.data()); @@ -3873,12 +3858,7 @@ void QRasterPaintEnginePrivate::rasterize(QT_FT_Outline *outline, } } -#if defined(Q_WS_WIN64) - _aligned_free(rasterPoolBase); -#else - if (rasterPoolBase != rasterPoolOnStack) // initially on the stack - free(rasterPoolBase); -#endif + free(rasterPoolOnHeap); } void QRasterPaintEnginePrivate::recalculateFastImages() -- cgit v0.12 From 7ab0bed3a56d46c386e65abc381264c57137cb43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Fri, 9 Sep 2011 09:51:18 +0200 Subject: Prevent QPixmapCache potentially growing indefinitely. QPixmapCache has until now refused to throw out shared pixmaps, i.e. ones that still have shallow copies lying around. This leads to problems when someone inserts two shallow copies using different keys, causing the cache itself containing multiple shallow copies and thus forever refusing to throw out those entries. It's rather easy for this to accidentally happen in a user application since QPixmap::load() or QPixmap(const QString &fileName, ...) automatically cache the pixmap in the QPixmapCache, thus if the user then calls QPixmapCache::insert() on the same pixmap or a shallow copy it is locked in the QPixmapCache forever. The only reason for not throwing out a pixmap that's shared would be to prevent re-loading a pixmap from file when a user has a direct reference to it in his application, but in that case the user is unlikely to re-load the pixmap from file in any case. Therefore it seems the best fix is to get rid of this limitation. Task-number: QTBUG-21359 Reviewed-by: John Brooks Reviewed-by: Olivier Goffart --- src/corelib/tools/qcache.h | 3 +-- tests/auto/qpixmapcache/tst_qpixmapcache.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/corelib/tools/qcache.h b/src/corelib/tools/qcache.h index 16861c9..2408cd3 100644 --- a/src/corelib/tools/qcache.h +++ b/src/corelib/tools/qcache.h @@ -205,8 +205,7 @@ void QCache::trim(int m) while (n && total > m) { Node *u = n; n = n->p; - if (qIsDetached(*u->t)) - unlink(*u); + unlink(*u); } } diff --git a/tests/auto/qpixmapcache/tst_qpixmapcache.cpp b/tests/auto/qpixmapcache/tst_qpixmapcache.cpp index 9f7192d..b36cf98 100644 --- a/tests/auto/qpixmapcache/tst_qpixmapcache.cpp +++ b/tests/auto/qpixmapcache/tst_qpixmapcache.cpp @@ -72,6 +72,7 @@ private slots: void clear(); void pixmapKey(); void noLeak(); + void strictCacheLimit(); }; static QPixmapCache::KeyData* getPrivate(QPixmapCache::Key &key) @@ -517,5 +518,29 @@ void tst_QPixmapCache::noLeak() QCOMPARE(oldSize, newSize); } + +void tst_QPixmapCache::strictCacheLimit() +{ + const int limit = 1024; // 1024 KB + + QPixmapCache::clear(); + QPixmapCache::setCacheLimit(limit); + + // insert 200 64x64 pixmaps + // 3200 KB for 32-bit depths + // 1600 KB for 16-bit depths + // not counting the duplicate entries + for (int i = 0; i < 200; ++i) { + QPixmap pixmap(64, 64); + pixmap.fill(Qt::transparent); + + QString id = QString::number(i); + QPixmapCache::insert(id + "-a", pixmap); + QPixmapCache::insert(id + "-b", pixmap); + } + + QVERIFY(QPixmapCache::totalUsed() <= limit); +} + QTEST_MAIN(tst_QPixmapCache) #include "tst_qpixmapcache.moc" -- cgit v0.12 From 1f803aeb390720336a23941f3d1ec71ef0e29083 Mon Sep 17 00:00:00 2001 From: Jiang Jiang Date: Fri, 9 Sep 2011 10:52:40 +0200 Subject: Reset trailingSpaces in relayout Reviewed-by: TrustMe --- src/gui/text/qtextlayout.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index cf361a0..4595ef5 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -1708,6 +1708,7 @@ void QTextLine::layout_helper(int maxGlyphs) { QScriptLine &line = eng->lines[i]; line.length = 0; + line.trailingSpaces = 0; line.textWidth = 0; line.hasTrailingSpaces = false; -- cgit v0.12 From cd43d6386de6e66379fa23c1ea4ec06141167c86 Mon Sep 17 00:00:00 2001 From: Aleksandar Stojiljkovic Date: Thu, 8 Sep 2011 12:00:41 +0300 Subject: Use QT_MAX_CACHED_GLYPH_SIZE in QFontEngineFT Task-number: QTBUG-21162 - Letters get truncated when font size=72 and set to Italic Reviewed-by: Eskil --- src/gui/text/qfontengine_ft.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/gui/text/qfontengine_ft.cpp b/src/gui/text/qfontengine_ft.cpp index 9a5d9d6..e3ab655 100644 --- a/src/gui/text/qfontengine_ft.cpp +++ b/src/gui/text/qfontengine_ft.cpp @@ -78,6 +78,10 @@ #include FT_ERRORS_H #endif +#if !defined(QT_MAX_CACHED_GLYPH_SIZE) +# define QT_MAX_CACHED_GLYPH_SIZE 64 +#endif + QT_BEGIN_NAMESPACE /* @@ -373,7 +377,7 @@ void QFreetypeFace::computeSize(const QFontDef &fontDef, int *xsize, int *ysize, *xsize = *ysize = 0; } } else { - *outline_drawing = (*xsize > (64<<6) || *ysize > (64<<6)); + *outline_drawing = (*xsize > (QT_MAX_CACHED_GLYPH_SIZE<<6) || *ysize > (QT_MAX_CACHED_GLYPH_SIZE<<6)); } } @@ -1317,7 +1321,7 @@ QFontEngineFT::QGlyphSet *QFontEngineFT::loadTransformedGlyphSet(const QTransfor if (!gs) { // don't try to load huge fonts - bool draw_as_outline = fontDef.pixelSize * qSqrt(qAbs(matrix.det())) >= 64; + bool draw_as_outline = fontDef.pixelSize * qSqrt(qAbs(matrix.det())) >= QT_MAX_CACHED_GLYPH_SIZE; if (draw_as_outline) return 0; -- cgit v0.12 From 43e013e2048e8193e2d31276cac6348a9f6ce340 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Fri, 2 Sep 2011 13:48:26 +0200 Subject: Generate glyphs in un-transformed coordinate system. Avoids rounding issues with very large coordinates. Task-number: QTBUG-21262 - QRasterPaintEngine & QFontEngineFT - fonts corrupted when scrolling to the bottom of long texts Reviewed-by: Eskil Signed-off-by: Aleksandar Stojiljkovic --- src/gui/painting/qpaintengine.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/gui/painting/qpaintengine.cpp b/src/gui/painting/qpaintengine.cpp index c46513a..38ba6f9 100644 --- a/src/gui/painting/qpaintengine.cpp +++ b/src/gui/painting/qpaintengine.cpp @@ -756,14 +756,15 @@ void QPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem) path.setFillRule(Qt::WindingFill); #endif if (ti.glyphs.numGlyphs) - ti.fontEngine->addOutlineToPath(p.x(), p.y(), ti.glyphs, &path, ti.flags); + ti.fontEngine->addOutlineToPath(0, 0, ti.glyphs, &path, ti.flags); if (!path.isEmpty()) { - bool oldAA = painter()->renderHints() & QPainter::Antialiasing; + painter()->save(); painter()->setRenderHint(QPainter::Antialiasing, bool((painter()->renderHints() & QPainter::TextAntialiasing) && !(painter()->font().styleStrategy() & QFont::NoAntialias))); + painter()->translate(p.x(), p.y()); painter()->fillPath(path, state->pen().brush()); - painter()->setRenderHint(QPainter::Antialiasing, oldAA); + painter()->restore(); } } -- cgit v0.12 From a193c14a01653d07d895d6305d9514310b8e3eba Mon Sep 17 00:00:00 2001 From: aavit Date: Sat, 10 Sep 2011 07:22:10 +0200 Subject: Disable autotest broken by the change to QCache in 7ab0bed Reviewed-by: trustme --- tests/auto/collections/tst_collections.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/auto/collections/tst_collections.cpp b/tests/auto/collections/tst_collections.cpp index 00cdec3..e13e1d9 100644 --- a/tests/auto/collections/tst_collections.cpp +++ b/tests/auto/collections/tst_collections.cpp @@ -2442,6 +2442,7 @@ void tst_Collections::cache() QVERIFY(!cache.contains(2)); delete cache.take(10); } +#if 0 { QCache cache(120); int i; @@ -2455,6 +2456,7 @@ void tst_Collections::cache() QVERIFY(!cache.contains(3)); QVERIFY(cache.contains(2)); } +#endif { QCache cache(100); cache.insert(2, new int(2)); @@ -3505,7 +3507,7 @@ void testVectorAlignment() for (int i = 0; i < 200; ++i) container.append(Aligned()); - + for (int i = 0; i < container.size(); ++i) QVERIFY(container.at(i).checkAligned()); } -- cgit v0.12