diff options
Diffstat (limited to 'src/gui/text')
28 files changed, 384 insertions, 257 deletions
diff --git a/src/gui/text/qabstracttextdocumentlayout.h b/src/gui/text/qabstracttextdocumentlayout.h index 438ad6e70b..8fea27f772 100644 --- a/src/gui/text/qabstracttextdocumentlayout.h +++ b/src/gui/text/qabstracttextdocumentlayout.h @@ -100,7 +100,7 @@ public: QTextDocument *document() const; void registerHandler(int objectType, QObject *component); - void unregisterHandler(int objectType, QObject *component = Q_NULLPTR); + void unregisterHandler(int objectType, QObject *component = nullptr); QTextObjectInterface *handlerForObject(int objectType) const; Q_SIGNALS: diff --git a/src/gui/text/qfont.cpp b/src/gui/text/qfont.cpp index 438cd3de3a..220e89a0c4 100644 --- a/src/gui/text/qfont.cpp +++ b/src/gui/text/qfont.cpp @@ -2849,7 +2849,7 @@ QFontEngine *QFontCache::findEngine(const Key &key) end = engineCache.end(); if (it == end) return 0; - Q_ASSERT(it.value().data != Q_NULLPTR); + Q_ASSERT(it.value().data != nullptr); Q_ASSERT(key.multi == (it.value().data->type() == QFontEngine::Multi)); // found... update the hitcount and timestamp @@ -2872,7 +2872,7 @@ void QFontCache::updateHitCountAndTimeStamp(Engine &value) void QFontCache::insertEngine(const Key &key, QFontEngine *engine, bool insertMulti) { - Q_ASSERT(engine != Q_NULLPTR); + Q_ASSERT(engine != nullptr); Q_ASSERT(key.multi == (engine->type() == QFontEngine::Multi)); #ifdef QFONTCACHE_DEBUG diff --git a/src/gui/text/qfont_p.h b/src/gui/text/qfont_p.h index 9e5d0b4329..350ba7ce3c 100644 --- a/src/gui/text/qfont_p.h +++ b/src/gui/text/qfont_p.h @@ -282,7 +282,7 @@ public: private: void increaseCost(uint cost); void decreaseCost(uint cost); - void timerEvent(QTimerEvent *event) Q_DECL_OVERRIDE; + void timerEvent(QTimerEvent *event) override; void decreaseCache(); static const uint min_cost; diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp index 33dc27983a..4be2197c68 100644 --- a/src/gui/text/qfontdatabase.cpp +++ b/src/gui/text/qfontdatabase.cpp @@ -804,6 +804,13 @@ QString qt_resolveFontFamilyAlias(const QString &alias) return alias; } +/*! + Returns a list of alternative fonts for the specified \a family and + \a style and \a script using the \a styleHint given. + + Default implementation returns a list of fonts for which \a style and \a script support + has been reported during the font database population. +*/ QStringList QPlatformFontDatabase::fallbacksForFamily(const QString &family, QFont::Style style, QFont::StyleHint styleHint, QChar::Script script) const { Q_UNUSED(family); @@ -2685,7 +2692,15 @@ QFontEngine *QFontDatabase::findFont(const QFontDef &request, int script) index = match(multi ? QChar::Script_Common : script, request, family_name, foundry_name, &desc, blackListed); } if (index >= 0) { - engine = loadEngine(script, request, desc.family, desc.foundry, desc.style, desc.size); + QFontDef fontDef = request; + + // Don't pass empty family names to the platform font database, since it will then invoke its own matching + // and we will be out of sync with the matched font. + if (fontDef.family.isEmpty()) + fontDef.family = desc.family->name; + + engine = loadEngine(script, fontDef, desc.family, desc.foundry, desc.style, desc.size); + if (engine) initFontDef(desc, request, &engine->fontDef, multi); else @@ -2775,7 +2790,7 @@ void QFontDatabase::load(const QFontPrivate *d, int script) if (d->engineData->engines[script]) return; - QFontEngine *fe = Q_NULLPTR; + QFontEngine *fe = nullptr; req.fallBackFamilies = fallBackFamilies; if (!req.fallBackFamilies.isEmpty()) diff --git a/src/gui/text/qfontengine.cpp b/src/gui/text/qfontengine.cpp index 33df020a6c..3b64ee0136 100644 --- a/src/gui/text/qfontengine.cpp +++ b/src/gui/text/qfontengine.cpp @@ -992,13 +992,12 @@ void QFontEngine::removeGlyphFromCache(glyph_t) QFontEngine::Properties QFontEngine::properties() const { Properties p; - QByteArray psname = QFontEngine::convertToPostscriptFontFamilyName(fontDef.family.toUtf8()); - psname += '-'; - psname += QByteArray::number(fontDef.style); - psname += '-'; - psname += QByteArray::number(fontDef.weight); - - p.postscriptName = psname; + p.postscriptName + = QFontEngine::convertToPostscriptFontFamilyName(fontDef.family.toUtf8()) + + '-' + + QByteArray::number(fontDef.style) + + '-' + + QByteArray::number(fontDef.weight); p.ascent = ascent(); p.descent = descent(); p.leading = leading(); @@ -1080,7 +1079,7 @@ QFontEngineGlyphCache *QFontEngine::glyphCache(const void *context, GlyphFormat { const QHash<const void*, GlyphCaches>::const_iterator caches = m_glyphCaches.constFind(context); if (caches == m_glyphCaches.cend()) - return Q_NULLPTR; + return nullptr; for (GlyphCaches::const_iterator it = caches->begin(), end = caches->end(); it != end; ++it) { QFontEngineGlyphCache *cache = it->cache.data(); @@ -1088,7 +1087,7 @@ QFontEngineGlyphCache *QFontEngine::glyphCache(const void *context, GlyphFormat return cache; } - return Q_NULLPTR; + return nullptr; } static inline QFixed kerning(int left, int right, const QFontEngine::KernPair *pairs, int numPairs) @@ -1234,7 +1233,7 @@ int QFontEngine::glyphCount() const Qt::HANDLE QFontEngine::handle() const { - return Q_NULLPTR; + return nullptr; } const uchar *QFontEngine::getCMap(const uchar *table, uint tableSize, bool *isSymbolFont, int *cmapSize) diff --git a/src/gui/text/qfontengine_p.h b/src/gui/text/qfontengine_p.h index 1ae2e86a93..a411e9ce4c 100644 --- a/src/gui/text/qfontengine_p.h +++ b/src/gui/text/qfontengine_p.h @@ -411,27 +411,27 @@ public: QFontEngineBox(int size); ~QFontEngineBox(); - virtual glyph_t glyphIndex(uint ucs4) const Q_DECL_OVERRIDE; - virtual bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, ShaperFlags flags) const Q_DECL_OVERRIDE; - virtual void recalcAdvances(QGlyphLayout *, ShaperFlags) const Q_DECL_OVERRIDE; + virtual glyph_t glyphIndex(uint ucs4) const override; + virtual bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, ShaperFlags flags) const override; + virtual void recalcAdvances(QGlyphLayout *, ShaperFlags) const override; void draw(QPaintEngine *p, qreal x, qreal y, const QTextItemInt &si); - virtual void addOutlineToPath(qreal x, qreal y, const QGlyphLayout &glyphs, QPainterPath *path, QTextItem::RenderFlags flags) Q_DECL_OVERRIDE; + virtual void addOutlineToPath(qreal x, qreal y, const QGlyphLayout &glyphs, QPainterPath *path, QTextItem::RenderFlags flags) override; - virtual glyph_metrics_t boundingBox(const QGlyphLayout &glyphs) Q_DECL_OVERRIDE; - virtual glyph_metrics_t boundingBox(glyph_t glyph) Q_DECL_OVERRIDE; - virtual QFontEngine *cloneWithSize(qreal pixelSize) const Q_DECL_OVERRIDE; + virtual glyph_metrics_t boundingBox(const QGlyphLayout &glyphs) override; + virtual glyph_metrics_t boundingBox(glyph_t glyph) override; + virtual QFontEngine *cloneWithSize(qreal pixelSize) const override; - virtual QFixed ascent() const Q_DECL_OVERRIDE; - virtual QFixed capHeight() const Q_DECL_OVERRIDE; - virtual QFixed descent() const Q_DECL_OVERRIDE; - virtual QFixed leading() const Q_DECL_OVERRIDE; - virtual qreal maxCharWidth() const Q_DECL_OVERRIDE; - virtual qreal minLeftBearing() const Q_DECL_OVERRIDE { return 0; } - virtual qreal minRightBearing() const Q_DECL_OVERRIDE { return 0; } - virtual QImage alphaMapForGlyph(glyph_t) Q_DECL_OVERRIDE; + virtual QFixed ascent() const override; + virtual QFixed capHeight() const override; + virtual QFixed descent() const override; + virtual QFixed leading() const override; + virtual qreal maxCharWidth() const override; + virtual qreal minLeftBearing() const override { return 0; } + virtual qreal minRightBearing() const override { return 0; } + virtual QImage alphaMapForGlyph(glyph_t) override; - virtual bool canRender(const QChar *string, int len) const Q_DECL_OVERRIDE; + virtual bool canRender(const QChar *string, int len) const override; inline int size() const { return _size; } @@ -449,36 +449,36 @@ public: explicit QFontEngineMulti(QFontEngine *engine, int script, const QStringList &fallbackFamilies = QStringList()); ~QFontEngineMulti(); - virtual glyph_t glyphIndex(uint ucs4) const Q_DECL_OVERRIDE; - virtual bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, ShaperFlags flags) const Q_DECL_OVERRIDE; - - virtual glyph_metrics_t boundingBox(const QGlyphLayout &glyphs) Q_DECL_OVERRIDE; - virtual glyph_metrics_t boundingBox(glyph_t glyph) Q_DECL_OVERRIDE; - - virtual void recalcAdvances(QGlyphLayout *, ShaperFlags) const Q_DECL_OVERRIDE; - virtual void doKerning(QGlyphLayout *, ShaperFlags) const Q_DECL_OVERRIDE; - virtual void addOutlineToPath(qreal, qreal, const QGlyphLayout &, QPainterPath *, QTextItem::RenderFlags flags) Q_DECL_OVERRIDE; - virtual void getGlyphBearings(glyph_t glyph, qreal *leftBearing = 0, qreal *rightBearing = 0) Q_DECL_OVERRIDE; - - virtual QFixed ascent() const Q_DECL_OVERRIDE; - virtual QFixed capHeight() const Q_DECL_OVERRIDE; - virtual QFixed descent() const Q_DECL_OVERRIDE; - virtual QFixed leading() const Q_DECL_OVERRIDE; - virtual QFixed xHeight() const Q_DECL_OVERRIDE; - virtual QFixed averageCharWidth() const Q_DECL_OVERRIDE; - virtual QImage alphaMapForGlyph(glyph_t) Q_DECL_OVERRIDE; - virtual QImage alphaMapForGlyph(glyph_t glyph, QFixed subPixelPosition) Q_DECL_OVERRIDE; - virtual QImage alphaMapForGlyph(glyph_t, const QTransform &t) Q_DECL_OVERRIDE; - virtual QImage alphaMapForGlyph(glyph_t, QFixed subPixelPosition, const QTransform &t) Q_DECL_OVERRIDE; - virtual QImage alphaRGBMapForGlyph(glyph_t, QFixed subPixelPosition, const QTransform &t) Q_DECL_OVERRIDE; - - virtual QFixed lineThickness() const Q_DECL_OVERRIDE; - virtual QFixed underlinePosition() const Q_DECL_OVERRIDE; - virtual qreal maxCharWidth() const Q_DECL_OVERRIDE; - virtual qreal minLeftBearing() const Q_DECL_OVERRIDE; - virtual qreal minRightBearing() const Q_DECL_OVERRIDE; - - virtual bool canRender(const QChar *string, int len) const Q_DECL_OVERRIDE; + virtual glyph_t glyphIndex(uint ucs4) const override; + virtual bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, ShaperFlags flags) const override; + + virtual glyph_metrics_t boundingBox(const QGlyphLayout &glyphs) override; + virtual glyph_metrics_t boundingBox(glyph_t glyph) override; + + virtual void recalcAdvances(QGlyphLayout *, ShaperFlags) const override; + virtual void doKerning(QGlyphLayout *, ShaperFlags) const override; + virtual void addOutlineToPath(qreal, qreal, const QGlyphLayout &, QPainterPath *, QTextItem::RenderFlags flags) override; + virtual void getGlyphBearings(glyph_t glyph, qreal *leftBearing = 0, qreal *rightBearing = 0) override; + + virtual QFixed ascent() const override; + virtual QFixed capHeight() const override; + virtual QFixed descent() const override; + virtual QFixed leading() const override; + virtual QFixed xHeight() const override; + virtual QFixed averageCharWidth() const override; + virtual QImage alphaMapForGlyph(glyph_t) override; + virtual QImage alphaMapForGlyph(glyph_t glyph, QFixed subPixelPosition) override; + virtual QImage alphaMapForGlyph(glyph_t, const QTransform &t) override; + virtual QImage alphaMapForGlyph(glyph_t, QFixed subPixelPosition, const QTransform &t) override; + virtual QImage alphaRGBMapForGlyph(glyph_t, QFixed subPixelPosition, const QTransform &t) override; + + virtual QFixed lineThickness() const override; + virtual QFixed underlinePosition() const override; + virtual qreal maxCharWidth() const override; + virtual qreal minLeftBearing() const override; + virtual qreal minRightBearing() const override; + + virtual bool canRender(const QChar *string, int len) const override; inline int fallbackFamilyCount() const { return m_fallbackFamilies.size(); } inline QString fallbackFamilyAt(int at) const { return m_fallbackFamilies.at(at); } diff --git a/src/gui/text/qfontengine_qpf2_p.h b/src/gui/text/qfontengine_qpf2_p.h index e5c38ffbaf..b2dc620ad1 100644 --- a/src/gui/text/qfontengine_qpf2_p.h +++ b/src/gui/text/qfontengine_qpf2_p.h @@ -158,30 +158,30 @@ public: QFontEngineQPF2(const QFontDef &def, const QByteArray &data); ~QFontEngineQPF2(); - FaceId faceId() const Q_DECL_OVERRIDE { return face_id; } - bool getSfntTableData(uint tag, uchar *buffer, uint *length) const Q_DECL_OVERRIDE; - - virtual glyph_t glyphIndex(uint ucs4) const Q_DECL_OVERRIDE; - bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, ShaperFlags flags) const Q_DECL_OVERRIDE; - void recalcAdvances(QGlyphLayout *, ShaperFlags) const Q_DECL_OVERRIDE; - - void addOutlineToPath(qreal x, qreal y, const QGlyphLayout &glyphs, QPainterPath *path, QTextItem::RenderFlags flags) Q_DECL_OVERRIDE; - QImage alphaMapForGlyph(glyph_t t) Q_DECL_OVERRIDE; - - glyph_metrics_t boundingBox(const QGlyphLayout &glyphs) Q_DECL_OVERRIDE; - glyph_metrics_t boundingBox(glyph_t glyph) Q_DECL_OVERRIDE; - - QFixed ascent() const Q_DECL_OVERRIDE; - QFixed capHeight() const Q_DECL_OVERRIDE; - QFixed descent() const Q_DECL_OVERRIDE; - QFixed leading() const Q_DECL_OVERRIDE; - qreal maxCharWidth() const Q_DECL_OVERRIDE; - qreal minLeftBearing() const Q_DECL_OVERRIDE; - qreal minRightBearing() const Q_DECL_OVERRIDE; - QFixed underlinePosition() const Q_DECL_OVERRIDE; - QFixed lineThickness() const Q_DECL_OVERRIDE; - - virtual int glyphCount() const Q_DECL_OVERRIDE { return glyphMapEntries; } + FaceId faceId() const override { return face_id; } + bool getSfntTableData(uint tag, uchar *buffer, uint *length) const override; + + virtual glyph_t glyphIndex(uint ucs4) const override; + bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, ShaperFlags flags) const override; + void recalcAdvances(QGlyphLayout *, ShaperFlags) const override; + + void addOutlineToPath(qreal x, qreal y, const QGlyphLayout &glyphs, QPainterPath *path, QTextItem::RenderFlags flags) override; + QImage alphaMapForGlyph(glyph_t t) override; + + glyph_metrics_t boundingBox(const QGlyphLayout &glyphs) override; + glyph_metrics_t boundingBox(glyph_t glyph) override; + + QFixed ascent() const override; + QFixed capHeight() const override; + QFixed descent() const override; + QFixed leading() const override; + qreal maxCharWidth() const override; + qreal minLeftBearing() const override; + qreal minRightBearing() const override; + QFixed underlinePosition() const override; + QFixed lineThickness() const override; + + virtual int glyphCount() const override { return glyphMapEntries; } bool isValid() const; diff --git a/src/gui/text/qfontmetrics.cpp b/src/gui/text/qfontmetrics.cpp index 5675d6921d..5ad57b064b 100644 --- a/src/gui/text/qfontmetrics.cpp +++ b/src/gui/text/qfontmetrics.cpp @@ -510,6 +510,7 @@ int QFontMetrics::rightBearing(QChar ch) const return qRound(rb); } +#if QT_DEPRECATED_SINCE(5, 11) /*! Returns the width in pixels of the first \a len characters of \a text. If \a len is negative (the default), the entire string is @@ -520,11 +521,13 @@ int QFontMetrics::rightBearing(QChar ch) const string will cover whereas width() returns the distance to where the next string should be drawn. + \deprecated in Qt 5.11. Use horizontalAdvance() instead. + \sa boundingRect() */ int QFontMetrics::width(const QString &text, int len) const { - return width(text, len, 0); + return horizontalAdvance(text, len); } /*! @@ -532,17 +535,17 @@ int QFontMetrics::width(const QString &text, int len) const */ int QFontMetrics::width(const QString &text, int len, int flags) const { - int pos = text.indexOf(QLatin1Char('\x9c')); - if (pos != -1) { - len = (len < 0) ? pos : qMin(pos, len); - } else if (len < 0) { - len = text.length(); - } - if (len == 0) - return 0; - -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +#if QT_DEPRECATED_SINCE(5, 11) && QT_VERSION < QT_VERSION_CHECK(6, 0, 0) if (flags & Qt::TextBypassShaping) { + int pos = text.indexOf(QLatin1Char('\x9c')); + if (pos != -1) { + len = (len < 0) ? pos : qMin(pos, len); + } else if (len < 0) { + len = text.length(); + } + if (len == 0) + return 0; + // Skip complex shaping, only use advances int numGlyphs = len; QVarLengthGlyphLayoutArray glyphs(numGlyphs); @@ -555,10 +558,11 @@ int QFontMetrics::width(const QString &text, int len, int flags) const width += glyphs.advances[i]; return qRound(width); } +#else + Q_UNUSED(flags) #endif - QStackTextEngine layout(text, QFont(d.data())); - return qRound(layout.width(0, len)); + return horizontalAdvance(text, len); } /*! @@ -577,6 +581,8 @@ int QFontMetrics::width(const QString &text, int len, int flags) const in this particular font are both negative, while the bearings of "o" are both positive. + \deprecated in Qt 5.11. Use horizontalAdvance() instead. + \warning This function will produce incorrect results for Arabic characters or non-spacing marks in the middle of a string, as the glyph shaping and positioning of marks that happens when @@ -587,6 +593,65 @@ int QFontMetrics::width(const QString &text, int len, int flags) const */ int QFontMetrics::width(QChar ch) const { + return horizontalAdvance(ch); +} +#endif // QT_DEPRECATED_SINCE(5, 11) + +/*! + Returns the horizontal advance in pixels of the first \a len characters of \a + text. If \a len is negative (the default), the entire string is + used. + + This is the distance appropriate for drawing a subsequent character + after \a text. + + \since 5.11 + + \sa boundingRect() +*/ +int QFontMetrics::horizontalAdvance(const QString &text, int len) const +{ + int pos = text.indexOf(QLatin1Char('\x9c')); + if (pos != -1) { + len = (len < 0) ? pos : qMin(pos, len); + } else if (len < 0) { + len = text.length(); + } + if (len == 0) + return 0; + + QStackTextEngine layout(text, QFont(d.data())); + return qRound(layout.width(0, len)); +} + +/*! + \overload + + \image bearings.png Bearings + + Returns the horizontal advance of character \a ch in pixels. This is a + distance appropriate for drawing a subsequent character after \a + ch. + + Some of the metrics are described in the image. The + central dark rectangles cover the logical horizontalAdvance() of each + character. The outer pale rectangles cover the leftBearing() and + rightBearing() of each character. Notice that the bearings of "f" + in this particular font are both negative, while the bearings of + "o" are both positive. + + \warning This function will produce incorrect results for Arabic + characters or non-spacing marks in the middle of a string, as the + glyph shaping and positioning of marks that happens when + processing strings cannot be taken into account. When implementing + an interactive text control, use QTextLayout instead. + + \since 5.11 + + \sa boundingRect() +*/ +int QFontMetrics::horizontalAdvance(QChar ch) const +{ if (QChar::category(ch.unicode()) == QChar::Mark_NonSpacing) return 0; @@ -677,7 +742,7 @@ int QFontMetrics::charWidth(const QString &text, int pos) const rectangle might be different than what the width() method returns. If you want to know the advance width of the string (to lay out - a set of strings next to each other), use width() instead. + a set of strings next to each other), use horizontalAdvance() instead. Newline characters are processed as normal characters, \e not as linebreaks. @@ -711,7 +776,7 @@ QRect QFontMetrics::boundingRect(const QString &text) const base line. \warning The width of the returned rectangle is not the advance width - of the character. Use boundingRect(const QString &) or width() instead. + of the character. Use boundingRect(const QString &) or horizontalAdvance() instead. \sa width() */ @@ -846,7 +911,7 @@ QSize QFontMetrics::size(int flags, const QString &text, int tabStops, int *tabA rectangle might be different than what the width() method returns. If you want to know the advance width of the string (to lay out - a set of strings next to each other), use width() instead. + a set of strings next to each other), use horizontalAdvance() instead. Newline characters are processed as normal characters, \e not as linebreaks. @@ -1396,6 +1461,7 @@ qreal QFontMetricsF::rightBearing(QChar ch) const } +#if QT_DEPRECATED_SINCE(5, 11) /*! Returns the width in pixels of the characters in the given \a text. @@ -1404,16 +1470,73 @@ qreal QFontMetricsF::rightBearing(QChar ch) const describing the pixels this string will cover whereas width() returns the distance to where the next string should be drawn. + \deprecated in Qt 5.11. Use horizontalAdvance() instead. + \sa boundingRect() */ qreal QFontMetricsF::width(const QString &text) const { + return horizontalAdvance(text); +} + +/*! + \overload + + \image bearings.png Bearings + + Returns the logical width of character \a ch in pixels. This is a + distance appropriate for drawing a subsequent character after \a + ch. + + Some of the metrics are described in the image to the right. The + central dark rectangles cover the logical width() of each + character. The outer pale rectangles cover the leftBearing() and + rightBearing() of each character. Notice that the bearings of "f" + in this particular font are both negative, while the bearings of + "o" are both positive. + + \deprecated in Qt 5.11. Use horizontalAdvance() instead. + + \warning This function will produce incorrect results for Arabic + characters or non-spacing marks in the middle of a string, as the + glyph shaping and positioning of marks that happens when + processing strings cannot be taken into account. When implementing + an interactive text control, use QTextLayout instead. + + \sa boundingRect() +*/ +qreal QFontMetricsF::width(QChar ch) const +{ + return horizontalAdvance(ch); +} +#endif + +/*! + Returns the horizontal advance in pixels of the first \a length characters of \a + text. If \a length is negative (the default), the entire string is + used. + + The advance is the distance appropriate for drawing a subsequent + character after \a text. + + \since 5.11 + + \sa boundingRect() +*/ +qreal QFontMetricsF::horizontalAdvance(const QString &text, int length) const +{ int pos = text.indexOf(QLatin1Char('\x9c')); - int len = (pos != -1) ? pos : text.length(); + if (pos != -1) + length = (length < 0) ? pos : qMin(pos, length); + else if (length < 0) + length = text.length(); + + if (length == 0) + return 0; QStackTextEngine layout(text, QFont(d.data())); layout.itemize(); - return layout.width(0, len).toReal(); + return layout.width(0, length).toReal(); } /*! @@ -1421,7 +1544,7 @@ qreal QFontMetricsF::width(const QString &text) const \image bearings.png Bearings - Returns the logical width of character \a ch in pixels. This is a + Returns the horizontal advance of character \a ch in pixels. This is a distance appropriate for drawing a subsequent character after \a ch. @@ -1438,9 +1561,11 @@ qreal QFontMetricsF::width(const QString &text) const processing strings cannot be taken into account. When implementing an interactive text control, use QTextLayout instead. + \since 5.11 + \sa boundingRect() */ -qreal QFontMetricsF::width(QChar ch) const +qreal QFontMetricsF::horizontalAdvance(QChar ch) const { if (ch.category() == QChar::Mark_NonSpacing) return 0.; @@ -1467,6 +1592,7 @@ qreal QFontMetricsF::width(QChar ch) const return advance.toReal(); } + /*! Returns the bounding rectangle of the characters in the string specified by \a text. The bounding rectangle always covers at least @@ -1477,7 +1603,7 @@ qreal QFontMetricsF::width(QChar ch) const rectangle might be different than what the width() method returns. If you want to know the advance width of the string (to lay out - a set of strings next to each other), use width() instead. + a set of strings next to each other), use horizontalAdvance() instead. Newline characters are processed as normal characters, \e not as linebreaks. @@ -1650,7 +1776,7 @@ QSizeF QFontMetricsF::size(int flags, const QString &text, int tabStops, int *ta rectangle might be different than what the width() method returns. If you want to know the advance width of the string (to lay out - a set of strings next to each other), use width() instead. + a set of strings next to each other), use horizontalAdvance() instead. Newline characters are processed as normal characters, \e not as linebreaks. diff --git a/src/gui/text/qfontmetrics.h b/src/gui/text/qfontmetrics.h index 3eac309092..b6167a1d47 100644 --- a/src/gui/text/qfontmetrics.h +++ b/src/gui/text/qfontmetrics.h @@ -90,10 +90,16 @@ public: int leftBearing(QChar) const; int rightBearing(QChar) const; + +#if QT_DEPRECATED_SINCE(5, 11) int width(const QString &, int len = -1) const; int width(const QString &, int len, int flags) const; - int width(QChar) const; +#endif + + int horizontalAdvance(const QString &, int len = -1) const; + int horizontalAdvance(QChar) const; + #if QT_VERSION < QT_VERSION_CHECK(6,0,0) QT_DEPRECATED int charWidth(const QString &str, int pos) const; #endif @@ -101,11 +107,11 @@ public: QRect boundingRect(QChar) const; QRect boundingRect(const QString &text) const; - QRect boundingRect(const QRect &r, int flags, const QString &text, int tabstops = 0, int *tabarray = Q_NULLPTR) const; + QRect boundingRect(const QRect &r, int flags, const QString &text, int tabstops = 0, int *tabarray = nullptr) const; inline QRect boundingRect(int x, int y, int w, int h, int flags, const QString &text, - int tabstops = 0, int *tabarray = Q_NULLPTR) const + int tabstops = 0, int *tabarray = nullptr) const { return boundingRect(QRect(x, y, w, h), flags, text, tabstops, tabarray); } - QSize size(int flags, const QString& str, int tabstops = 0, int *tabarray = Q_NULLPTR) const; + QSize size(int flags, const QString& str, int tabstops = 0, int *tabarray = nullptr) const; QRect tightBoundingRect(const QString &text) const; @@ -164,14 +170,19 @@ public: qreal leftBearing(QChar) const; qreal rightBearing(QChar) const; - qreal width(const QString &string) const; +#if QT_DEPRECATED_SINCE(5, 11) + qreal width(const QString &string) const; qreal width(QChar) const; +#endif + + qreal horizontalAdvance(const QString &string, int length = -1) const; + qreal horizontalAdvance(QChar) const; QRectF boundingRect(const QString &string) const; QRectF boundingRect(QChar) const; - QRectF boundingRect(const QRectF &r, int flags, const QString& string, int tabstops = 0, int *tabarray = Q_NULLPTR) const; - QSizeF size(int flags, const QString& str, int tabstops = 0, int *tabarray = Q_NULLPTR) const; + QRectF boundingRect(const QRectF &r, int flags, const QString& string, int tabstops = 0, int *tabarray = nullptr) const; + QSizeF size(int flags, const QString& str, int tabstops = 0, int *tabarray = nullptr) const; QRectF tightBoundingRect(const QString &text) const; diff --git a/src/gui/text/qharfbuzzng.cpp b/src/gui/text/qharfbuzzng.cpp index 6aca660205..36bd81c76b 100644 --- a/src/gui/text/qharfbuzzng.cpp +++ b/src/gui/text/qharfbuzzng.cpp @@ -202,7 +202,21 @@ static const hb_script_t _qtscript_to_hbscript[] = { HB_SCRIPT_HATRAN, HB_SCRIPT_MULTANI, HB_SCRIPT_OLD_HUNGARIAN, - HB_SCRIPT_SIGNWRITING + HB_SCRIPT_SIGNWRITING, + + // Unicode 9.0 additions + HB_SCRIPT_ADLAM, + HB_SCRIPT_BHAIKSUKI, + HB_SCRIPT_MARCHEN, + HB_SCRIPT_NEWA, + HB_SCRIPT_OSAGE, + HB_SCRIPT_TANGUT, + + // Unicode 10.0 additions + HB_SCRIPT_MASARAM_GONDI, + HB_SCRIPT_NUSHU, + HB_SCRIPT_SOYOMBO, + HB_SCRIPT_ZANABAZAR_SQUARE }; Q_STATIC_ASSERT(QChar::ScriptCount == sizeof(_qtscript_to_hbscript) / sizeof(_qtscript_to_hbscript[0])); @@ -422,7 +436,6 @@ hb_unicode_funcs_t *hb_qt_get_unicode_funcs() // Font routines -#if HB_VERSION_ATLEAST(1, 1, 3) static hb_bool_t _hb_qt_get_font_h_extents(hb_font_t * /*font*/, void *font_data, hb_font_extents_t *metrics, @@ -437,9 +450,7 @@ _hb_qt_get_font_h_extents(hb_font_t * /*font*/, void *font_data, return true; } -#endif -#if HB_VERSION_ATLEAST(1, 2, 3) static hb_bool_t _hb_qt_font_get_nominal_glyph(hb_font_t * /*font*/, void *font_data, hb_codepoint_t unicode, @@ -453,7 +464,6 @@ _hb_qt_font_get_nominal_glyph(hb_font_t * /*font*/, void *font_data, return *glyph != 0; } -#endif static hb_bool_t _hb_qt_font_get_variation_glyph(hb_font_t * /*font*/, void *font_data, @@ -490,17 +500,6 @@ _hb_qt_font_get_glyph_h_advance(hb_font_t *font, void *font_data, return advance.value(); } -#if !HB_VERSION_ATLEAST(1, 1, 2) -static hb_bool_t -_hb_qt_font_get_glyph_h_origin(hb_font_t * /*font*/, void * /*font_data*/, - hb_codepoint_t /*glyph*/, - hb_position_t * /*x*/, hb_position_t * /*y*/, - void * /*user_data*/) -{ - return true; // we always work in the horizontal coordinates -} -#endif - static hb_position_t _hb_qt_font_get_glyph_h_kerning(hb_font_t *font, void *font_data, hb_codepoint_t first_glyph, hb_codepoint_t second_glyph, @@ -581,19 +580,10 @@ struct _hb_qt_font_funcs_t { { funcs = hb_font_funcs_create(); -#if HB_VERSION_ATLEAST(1, 1, 3) hb_font_funcs_set_font_h_extents_func(funcs, _hb_qt_get_font_h_extents, NULL, NULL); -#endif -#if HB_VERSION_ATLEAST(1, 2, 3) hb_font_funcs_set_nominal_glyph_func(funcs, _hb_qt_font_get_nominal_glyph, NULL, NULL); hb_font_funcs_set_variation_glyph_func(funcs, _hb_qt_font_get_variation_glyph, NULL, NULL); -#else - hb_font_funcs_set_glyph_func(funcs, _hb_qt_font_get_variation_glyph, NULL, NULL); -#endif hb_font_funcs_set_glyph_h_advance_func(funcs, _hb_qt_font_get_glyph_h_advance, NULL, NULL); -#if !HB_VERSION_ATLEAST(1, 1, 2) - hb_font_funcs_set_glyph_h_origin_func(funcs, _hb_qt_font_get_glyph_h_origin, NULL, NULL); -#endif hb_font_funcs_set_glyph_h_kerning_func(funcs, _hb_qt_font_get_glyph_h_kerning, NULL, NULL); hb_font_funcs_set_glyph_extents_func(funcs, _hb_qt_font_get_glyph_extents, NULL, NULL); hb_font_funcs_set_glyph_contour_point_func(funcs, _hb_qt_font_get_glyph_contour_point, NULL, NULL); diff --git a/src/gui/text/qplatformfontdatabase.cpp b/src/gui/text/qplatformfontdatabase.cpp index 4ad826e87b..d89805d18e 100644 --- a/src/gui/text/qplatformfontdatabase.cpp +++ b/src/gui/text/qplatformfontdatabase.cpp @@ -62,8 +62,6 @@ void qt_registerFontFamily(const QString &familyName); void qt_registerAliasToFontFamily(const QString &familyName, const QString &alias); /*! - \fn void QPlatformFontDatabase::registerQPF2Font(const QByteArray &dataArray, void *handle) - Registers the pre-rendered QPF2 font contained in the given \a dataArray. \sa registerFont() @@ -373,17 +371,6 @@ QFontEngine *QPlatformFontDatabase::fontEngine(const QByteArray &fontData, qreal } /*! - \fn QStringList QPlatformFontDatabase::fallbacksForFamily(const QString &family, QFont::Style style, QFont::StyleHint styleHint, QChar::Script script) const - - Returns a list of alternative fonts for the specified \a family and - \a style and \a script using the \a styleHint given. - - Default implementation returns a list of fonts for which \a style and \a script support - has been reported during the font database population. -*/ -// implemented in qfontdatabase.cpp - -/*! Adds an application font described by the font contained supplied \a fontData or using the font contained in the file referenced by \a fileName. Returns a list of family names, or an empty list if the font could not be added. diff --git a/src/gui/text/qstatictext.cpp b/src/gui/text/qstatictext.cpp index dbc2e6e558..2f90754274 100644 --- a/src/gui/text/qstatictext.cpp +++ b/src/gui/text/qstatictext.cpp @@ -435,11 +435,11 @@ namespace { public: DrawTextItemRecorder(bool untransformedCoordinates, bool useBackendOptimizations) : m_dirtyPen(false), m_useBackendOptimizations(useBackendOptimizations), - m_untransformedCoordinates(untransformedCoordinates), m_currentColor(Qt::black) + m_untransformedCoordinates(untransformedCoordinates), m_currentColor(0, 0, 0, 0) { } - virtual void updateState(const QPaintEngineState &newState) Q_DECL_OVERRIDE + virtual void updateState(const QPaintEngineState &newState) override { if (newState.state() & QPaintEngine::DirtyPen && newState.pen().color() != m_currentColor) { @@ -448,7 +448,7 @@ namespace { } } - virtual void drawTextItem(const QPointF &position, const QTextItem &textItem) Q_DECL_OVERRIDE + virtual void drawTextItem(const QPointF &position, const QTextItem &textItem) override { const QTextItemInt &ti = static_cast<const QTextItemInt &>(textItem); @@ -484,15 +484,15 @@ namespace { m_items.append(currentItem); } - virtual void drawPolygon(const QPointF *, int , PolygonDrawMode ) Q_DECL_OVERRIDE + virtual void drawPolygon(const QPointF *, int , PolygonDrawMode ) override { /* intentionally empty */ } - virtual bool begin(QPaintDevice *) Q_DECL_OVERRIDE { return true; } - virtual bool end() Q_DECL_OVERRIDE { return true; } - virtual void drawPixmap(const QRectF &, const QPixmap &, const QRectF &) Q_DECL_OVERRIDE {} - virtual Type type() const Q_DECL_OVERRIDE + virtual bool begin(QPaintDevice *) override { return true; } + virtual bool end() override { return true; } + virtual void drawPixmap(const QRectF &, const QPixmap &, const QRectF &) override {} + virtual Type type() const override { return User; } @@ -537,7 +537,7 @@ namespace { delete m_paintEngine; } - int metric(PaintDeviceMetric m) const Q_DECL_OVERRIDE + int metric(PaintDeviceMetric m) const override { int val; switch (m) { @@ -574,7 +574,7 @@ namespace { return val; } - virtual QPaintEngine *paintEngine() const Q_DECL_OVERRIDE + virtual QPaintEngine *paintEngine() const override { return m_paintEngine; } @@ -599,7 +599,7 @@ namespace { }; } -void QStaticTextPrivate::paintText(const QPointF &topLeftPosition, QPainter *p) +void QStaticTextPrivate::paintText(const QPointF &topLeftPosition, QPainter *p, const QColor &pen) { bool preferRichText = textFormat == Qt::RichText || (textFormat == Qt::AutoText && Qt::mightBeRichText(text)); @@ -631,15 +631,16 @@ void QStaticTextPrivate::paintText(const QPointF &topLeftPosition, QPainter *p) textLayout.endLayout(); actualSize = textLayout.boundingRect().size(); + p->setPen(pen); textLayout.draw(p, topLeftPosition); } else { QTextDocument document; #ifndef QT_NO_CSSPARSER - QColor color = p->pen().color(); - document.setDefaultStyleSheet(QString::fromLatin1("body { color: #%1%2%3 }") - .arg(QString::number(color.red(), 16), 2, QLatin1Char('0')) - .arg(QString::number(color.green(), 16), 2, QLatin1Char('0')) - .arg(QString::number(color.blue(), 16), 2, QLatin1Char('0'))); + document.setDefaultStyleSheet(QString::fromLatin1("body { color: rgba(%1, %2, %3, %4%) }") + .arg(QString::number(pen.red())) + .arg(QString::number(pen.green())) + .arg(QString::number(pen.blue())) + .arg(QString::number(pen.alpha()))); #endif document.setDefaultFont(font); document.setDocumentMargin(0.0); @@ -657,13 +658,10 @@ void QStaticTextPrivate::paintText(const QPointF &topLeftPosition, QPainter *p) p->save(); p->translate(topLeftPosition); QAbstractTextDocumentLayout::PaintContext ctx; - ctx.palette.setColor(QPalette::Text, p->pen().color()); + ctx.palette.setColor(QPalette::Text, pen); document.documentLayout()->draw(p, ctx); p->restore(); - if (textWidth >= 0.0) - document.adjustSize(); // Find optimal size - actualSize = document.size(); } } @@ -682,7 +680,7 @@ void QStaticTextPrivate::init() painter.setFont(font); painter.setTransform(matrix); - paintText(QPointF(0, 0), &painter); + paintText(QPointF(0, 0), &painter, QColor(0, 0, 0, 0)); } QVector<QStaticTextItem> deviceItems = device.items(); diff --git a/src/gui/text/qstatictext_p.h b/src/gui/text/qstatictext_p.h index dda566a22b..c4023488ff 100644 --- a/src/gui/text/qstatictext_p.h +++ b/src/gui/text/qstatictext_p.h @@ -131,7 +131,7 @@ public: ~QStaticTextPrivate(); void init(); - void paintText(const QPointF &pos, QPainter *p); + void paintText(const QPointF &pos, QPainter *p, const QColor &pen); void invalidate() { diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index db0650d154..931c9d7490 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -74,6 +74,8 @@ QT_BEGIN_NAMESPACE Q_CORE_EXPORT Q_DECL_CONST_FUNCTION unsigned int qt_int_sqrt(unsigned int n); /*! + \fn bool Qt::mightBeRichText(const QString& text) + Returns \c true if the string \a text is likely to be rich text; otherwise returns \c false. @@ -144,6 +146,8 @@ bool Qt::mightBeRichText(const QString& text) /*! + \fn QString Qt::convertFromPlainText(const QString &plain, Qt::WhiteSpaceMode mode) + Converts the plain text string \a plain to an HTML-formatted paragraph while preserving most of its look. @@ -805,7 +809,7 @@ void QTextDocument::adjustSize() // Pull this private function in from qglobal.cpp QFont f = defaultFont(); QFontMetrics fm(f); - int mw = fm.width(QLatin1Char('x')) * 80; + int mw = fm.horizontalAdvance(QLatin1Char('x')) * 80; int w = mw; setTextWidth(w); QSizeF size = documentLayout()->documentSize(); @@ -970,7 +974,7 @@ QString QTextDocument::defaultStyleSheet() const /*! - \fn QTextDocument::undoAvailable(bool available); + \fn void QTextDocument::undoAvailable(bool available); This signal is emitted whenever undo operations become available (\a available is true) or unavailable (\a available is false). @@ -982,14 +986,14 @@ QString QTextDocument::defaultStyleSheet() const */ /*! - \fn QTextDocument::redoAvailable(bool available); + \fn void QTextDocument::redoAvailable(bool available); This signal is emitted whenever redo operations become available (\a available is true) or unavailable (\a available is false). */ /*! - \fn QTextDocument::cursorPositionChanged(const QTextCursor &cursor); + \fn void QTextDocument::cursorPositionChanged(const QTextCursor &cursor); This signal is emitted whenever the position of a cursor changed due to an editing operation. The cursor that changed is passed in @@ -999,7 +1003,7 @@ QString QTextDocument::defaultStyleSheet() const */ /*! - \fn QTextDocument::blockCountChanged(int newBlockCount); + \fn void QTextDocument::blockCountChanged(int newBlockCount); \since 4.3 This signal is emitted when the total number of text blocks in the @@ -1008,7 +1012,7 @@ QString QTextDocument::defaultStyleSheet() const */ /*! - \fn QTextDocument::documentLayoutChanged(); + \fn void QTextDocument::documentLayoutChanged(); \since 4.4 This signal is emitted when a new document layout is set. @@ -1841,7 +1845,7 @@ QFont QTextDocument::defaultFont() const } /*! - \fn QTextDocument::modificationChanged(bool changed) + \fn void QTextDocument::modificationChanged(bool changed) This signal is emitted whenever the content of the document changes in a way that affects the modification state. If \a @@ -1898,7 +1902,7 @@ static void printPage(int index, QPainter *painter, const QTextDocument *doc, co painter->setFont(QFont(doc->defaultFont())); const QString pageString = QString::number(index); - painter->drawText(qRound(pageNumberPos.x() - painter->fontMetrics().width(pageString)), + painter->drawText(qRound(pageNumberPos.x() - painter->fontMetrics().horizontalAdvance(pageString)), qRound(pageNumberPos.y() + view.top()), pageString); } diff --git a/src/gui/text/qtextdocument.h b/src/gui/text/qtextdocument.h index c2761a39b9..41c578fc1b 100644 --- a/src/gui/text/qtextdocument.h +++ b/src/gui/text/qtextdocument.h @@ -116,11 +116,11 @@ class Q_GUI_EXPORT QTextDocument : public QObject Q_PROPERTY(QUrl baseUrl READ baseUrl WRITE setBaseUrl NOTIFY baseUrlChanged) public: - explicit QTextDocument(QObject *parent = Q_NULLPTR); - explicit QTextDocument(const QString &text, QObject *parent = Q_NULLPTR); + explicit QTextDocument(QObject *parent = nullptr); + explicit QTextDocument(const QString &text, QObject *parent = nullptr); ~QTextDocument(); - QTextDocument *clone(QObject *parent = Q_NULLPTR) const; + QTextDocument *clone(QObject *parent = nullptr) const; bool isEmpty() const; virtual void clear(); diff --git a/src/gui/text/qtextdocumentlayout.cpp b/src/gui/text/qtextdocumentlayout.cpp index e9194e73ff..9877a23fa6 100644 --- a/src/gui/text/qtextdocumentlayout.cpp +++ b/src/gui/text/qtextdocumentlayout.cpp @@ -1427,7 +1427,7 @@ void QTextDocumentLayoutPrivate::drawListItem(const QPointF &offset, QPainter *p case QTextListFormat::ListLowerRoman: case QTextListFormat::ListUpperRoman: itemText = static_cast<QTextList *>(object)->itemText(bl); - size.setWidth(fontMetrics.width(itemText)); + size.setWidth(fontMetrics.horizontalAdvance(itemText)); size.setHeight(fontMetrics.height()); break; @@ -1445,7 +1445,7 @@ void QTextDocumentLayoutPrivate::drawListItem(const QPointF &offset, QPainter *p QRectF r(pos, size); - qreal xoff = fontMetrics.width(QLatin1Char(' ')); + qreal xoff = fontMetrics.horizontalAdvance(QLatin1Char(' ')); if (dir == Qt::LeftToRight) xoff = -xoff - size.width(); r.translate( xoff, (fontMetrics.height() / 2) - (size.height() / 2)); @@ -2613,7 +2613,7 @@ void QTextDocumentLayoutPrivate::layoutBlock(const QTextBlock &bl, int blockPosi QFixed extraMargin; if (docPrivate->defaultTextOption.flags() & QTextOption::AddSpaceForLineAndParagraphSeparators) { QFontMetricsF fm(bl.charFormat().font()); - extraMargin = QFixed::fromReal(fm.width(QChar(QChar(0x21B5)))); + extraMargin = QFixed::fromReal(fm.horizontalAdvance(QChar(QChar(0x21B5)))); } const QFixed indent = this->blockIndent(blockFormat); diff --git a/src/gui/text/qtextdocumentlayout_p.h b/src/gui/text/qtextdocumentlayout_p.h index 710c49628e..2054ebaa35 100644 --- a/src/gui/text/qtextdocumentlayout_p.h +++ b/src/gui/text/qtextdocumentlayout_p.h @@ -73,11 +73,11 @@ public: explicit QTextDocumentLayout(QTextDocument *doc); // from the abstract layout - void draw(QPainter *painter, const PaintContext &context) Q_DECL_OVERRIDE; - int hitTest(const QPointF &point, Qt::HitTestAccuracy accuracy) const Q_DECL_OVERRIDE; + void draw(QPainter *painter, const PaintContext &context) override; + int hitTest(const QPointF &point, Qt::HitTestAccuracy accuracy) const override; - int pageCount() const Q_DECL_OVERRIDE; - QSizeF documentSize() const Q_DECL_OVERRIDE; + int pageCount() const override; + QSizeF documentSize() const override; void setCursorWidth(int width); int cursorWidth() const; @@ -88,8 +88,8 @@ public: // internal for QTextEdit's NoWrap mode void setViewport(const QRectF &viewport); - virtual QRectF frameBoundingRect(QTextFrame *frame) const Q_DECL_OVERRIDE; - virtual QRectF blockBoundingRect(const QTextBlock &block) const Q_DECL_OVERRIDE; + virtual QRectF frameBoundingRect(QTextFrame *frame) const override; + virtual QRectF blockBoundingRect(const QTextBlock &block) const override; QRectF tableBoundingRect(QTextTable *table) const; QRectF tableCellBoundingRect(QTextTable *table, const QTextTableCell &cell) const; @@ -104,12 +104,12 @@ public: bool contentHasAlignment() const; protected: - void documentChanged(int from, int oldLength, int length) Q_DECL_OVERRIDE; - void resizeInlineObject(QTextInlineObject item, int posInDocument, const QTextFormat &format) Q_DECL_OVERRIDE; - void positionInlineObject(QTextInlineObject item, int posInDocument, const QTextFormat &format) Q_DECL_OVERRIDE; + void documentChanged(int from, int oldLength, int length) override; + void resizeInlineObject(QTextInlineObject item, int posInDocument, const QTextFormat &format) override; + void positionInlineObject(QTextInlineObject item, int posInDocument, const QTextFormat &format) override; void drawInlineObject(QPainter *p, const QRectF &rect, QTextInlineObject item, - int posInDocument, const QTextFormat &format) Q_DECL_OVERRIDE; - virtual void timerEvent(QTimerEvent *e) Q_DECL_OVERRIDE; + int posInDocument, const QTextFormat &format) override; + virtual void timerEvent(QTimerEvent *e) override; private: QRectF doLayout(int from, int oldLength, int length); void layoutFinished(); diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp index faddb3552d..71f02376ac 100644 --- a/src/gui/text/qtextengine.cpp +++ b/src/gui/text/qtextengine.cpp @@ -1242,7 +1242,7 @@ int QTextEngine::shapeTextWithHarfbuzzNG(const QScriptItem &si, { HB_TAG('h','l','i','g'), !dontLigate, 0, uint(-1) } }; const int num_features = dontLigate ? 5 : 1; - const char *const *shaper_list = Q_NULLPTR; + const char *const *shaper_list = nullptr; #if defined(Q_OS_DARWIN) // What's behind QFontEngine::FaceData::user_data isn't compatible between different font engines // - specifically functions in hb-coretext.cc would run into undefined behavior with data @@ -1252,7 +1252,7 @@ int QTextEngine::shapeTextWithHarfbuzzNG(const QScriptItem &si, "graphite2", "ot", "fallback", - Q_NULLPTR + nullptr }; shaper_list = s_shaper_list_without_coretext; } diff --git a/src/gui/text/qtextformat.cpp b/src/gui/text/qtextformat.cpp index 8fe474af2c..08106db6ce 100644 --- a/src/gui/text/qtextformat.cpp +++ b/src/gui/text/qtextformat.cpp @@ -201,8 +201,10 @@ public: inline void insertProperty(qint32 key, const QVariant &value) { hashDirty = true; - if (key >= QTextFormat::FirstFontProperty && key <= QTextFormat::LastFontProperty) + if ((key >= QTextFormat::FirstFontProperty && key <= QTextFormat::LastFontProperty) + || key == QTextFormat::FontLetterSpacingType) { fontDirty = true; + } for (int i = 0; i < props.count(); ++i) if (props.at(i).key == key) { props[i].value = value; @@ -216,8 +218,10 @@ public: for (int i = 0; i < props.count(); ++i) if (props.at(i).key == key) { hashDirty = true; - if (key >= QTextFormat::FirstFontProperty && key <= QTextFormat::LastFontProperty) + if ((key >= QTextFormat::FirstFontProperty && key <= QTextFormat::LastFontProperty) + || key == QTextFormat::FontLetterSpacingType) { fontDirty = true; + } props.remove(i); return; } @@ -2584,13 +2588,13 @@ QTextFrameFormat::QTextFrameFormat(const QTextFormat &fmt) } /*! - \fn QTextFrameFormat::isValid() const + \fn bool QTextFrameFormat::isValid() const Returns \c true if the format description is valid; otherwise returns \c false. */ /*! - \fn QTextFrameFormat::setPosition(Position policy) + \fn void QTextFrameFormat::setPosition(Position policy) Sets the \a policy for positioning frames with this frame format. @@ -2603,7 +2607,7 @@ QTextFrameFormat::QTextFrameFormat(const QTextFormat &fmt) */ /*! - \fn QTextFrameFormat::setBorder(qreal width) + \fn void QTextFrameFormat::setBorder(qreal width) Sets the \a width (in pixels) of the frame's border. */ @@ -2615,7 +2619,7 @@ QTextFrameFormat::QTextFrameFormat(const QTextFormat &fmt) */ /*! - \fn QTextFrameFormat::setBorderBrush(const QBrush &brush) + \fn void QTextFrameFormat::setBorderBrush(const QBrush &brush) \since 4.3 Sets the \a brush used for the frame's border. @@ -2629,7 +2633,7 @@ QTextFrameFormat::QTextFrameFormat(const QTextFormat &fmt) */ /*! - \fn QTextFrameFormat::setBorderStyle(BorderStyle style) + \fn void QTextFrameFormat::setBorderStyle(BorderStyle style) \since 4.3 Sets the \a style of the frame's border. @@ -2643,7 +2647,7 @@ QTextFrameFormat::QTextFrameFormat(const QTextFormat &fmt) */ /*! - \fn QTextFrameFormat::setMargin(qreal margin) + \fn void QTextFrameFormat::setMargin(qreal margin) Sets the frame's \a margin in pixels. This method also sets the left, right, top and bottom margins @@ -2667,7 +2671,7 @@ void QTextFrameFormat::setMargin(qreal amargin) */ /*! - \fn QTextFrameFormat::setTopMargin(qreal margin) + \fn void QTextFrameFormat::setTopMargin(qreal margin) \since 4.3 Sets the frame's top \a margin in pixels. @@ -2687,7 +2691,7 @@ qreal QTextFrameFormat::topMargin() const } /*! - \fn QTextFrameFormat::setBottomMargin(qreal margin) + \fn void QTextFrameFormat::setBottomMargin(qreal margin) \since 4.3 Sets the frame's bottom \a margin in pixels. @@ -2707,7 +2711,7 @@ qreal QTextFrameFormat::bottomMargin() const } /*! - \fn QTextFrameFormat::setLeftMargin(qreal margin) + \fn void QTextFrameFormat::setLeftMargin(qreal margin) \since 4.3 Sets the frame's left \a margin in pixels. @@ -2727,7 +2731,7 @@ qreal QTextFrameFormat::leftMargin() const } /*! - \fn QTextFrameFormat::setRightMargin(qreal margin) + \fn void QTextFrameFormat::setRightMargin(qreal margin) \since 4.3 Sets the frame's right \a margin in pixels. @@ -2747,7 +2751,7 @@ qreal QTextFrameFormat::rightMargin() const } /*! - \fn QTextFrameFormat::setPadding(qreal width) + \fn void QTextFrameFormat::setPadding(qreal width) Sets the \a width of the frame's internal padding in pixels. */ @@ -2759,7 +2763,7 @@ qreal QTextFrameFormat::rightMargin() const */ /*! - \fn QTextFrameFormat::setWidth(const QTextLength &width) + \fn void QTextFrameFormat::setWidth(const QTextLength &width) Sets the frame's border rectangle's \a width. @@ -2767,7 +2771,7 @@ qreal QTextFrameFormat::rightMargin() const */ /*! - \fn QTextFrameFormat::setWidth(qreal width) + \fn void QTextFrameFormat::setWidth(qreal width) \overload Convenience method that sets the width of the frame's border diff --git a/src/gui/text/qtexthtmlparser.cpp b/src/gui/text/qtexthtmlparser.cpp index be10efad8d..9154182df1 100644 --- a/src/gui/text/qtexthtmlparser.cpp +++ b/src/gui/text/qtexthtmlparser.cpp @@ -1708,14 +1708,14 @@ public: inline QTextHtmlStyleSelector(const QTextHtmlParser *parser) : parser(parser) { nameCaseSensitivity = Qt::CaseInsensitive; } - virtual QStringList nodeNames(NodePtr node) const Q_DECL_OVERRIDE; - virtual QString attribute(NodePtr node, const QString &name) const Q_DECL_OVERRIDE; - virtual bool hasAttributes(NodePtr node) const Q_DECL_OVERRIDE; - virtual bool isNullNode(NodePtr node) const Q_DECL_OVERRIDE; - virtual NodePtr parentNode(NodePtr node) const Q_DECL_OVERRIDE; - virtual NodePtr previousSiblingNode(NodePtr node) const Q_DECL_OVERRIDE; - virtual NodePtr duplicateNode(NodePtr node) const Q_DECL_OVERRIDE; - virtual void freeNode(NodePtr node) const Q_DECL_OVERRIDE; + virtual QStringList nodeNames(NodePtr node) const override; + virtual QString attribute(NodePtr node, const QString &name) const override; + virtual bool hasAttributes(NodePtr node) const override; + virtual bool isNullNode(NodePtr node) const override; + virtual NodePtr parentNode(NodePtr node) const override; + virtual NodePtr previousSiblingNode(NodePtr node) const override; + virtual NodePtr duplicateNode(NodePtr node) const override; + virtual void freeNode(NodePtr node) const override; private: const QTextHtmlParser *parser; diff --git a/src/gui/text/qtextimagehandler_p.h b/src/gui/text/qtextimagehandler_p.h index a22c91ecbf..339ef0af4f 100644 --- a/src/gui/text/qtextimagehandler_p.h +++ b/src/gui/text/qtextimagehandler_p.h @@ -67,8 +67,8 @@ class Q_GUI_EXPORT QTextImageHandler : public QObject, public: explicit QTextImageHandler(QObject *parent = 0); - virtual QSizeF intrinsicSize(QTextDocument *doc, int posInDocument, const QTextFormat &format) Q_DECL_OVERRIDE; - virtual void drawObject(QPainter *p, const QRectF &rect, QTextDocument *doc, int posInDocument, const QTextFormat &format) Q_DECL_OVERRIDE; + virtual QSizeF intrinsicSize(QTextDocument *doc, int posInDocument, const QTextFormat &format) override; + virtual void drawObject(QPainter *p, const QRectF &rect, QTextDocument *doc, int posInDocument, const QTextFormat &format) override; QImage image(QTextDocument *doc, const QTextImageFormat &imageFormat); }; diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index 066f258ea3..87f73e1e83 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -93,14 +93,14 @@ QT_BEGIN_NAMESPACE Specifies the format to apply. */ -/*! \fn bool operator==(const FormatRange &lhs, const FormatRange &rhs) +/*! \fn bool operator==(const QTextLayout::FormatRange &lhs, const QTextLayout::FormatRange &rhs) \relates QTextLayout::FormatRange Returns true if the \c {start}, \c {length}, and \c {format} fields in \a lhs and \a rhs contain the same values respectively. */ -/*! \fn bool operator!=(const FormatRange &lhs, const FormatRange &rhs) +/*! \fn bool operator!=(const QTextLayout::FormatRange &lhs, const QTextLayout::FormatRange &rhs) \relates QTextLayout::FormatRange Returns true if any of the \c {start}, \c {length}, or \c {format} fields @@ -2453,7 +2453,7 @@ void QTextLine::draw(QPainter *p, const QPointF &pos, const QTextLayout::FormatR const qreal lineHeight = line.height().toReal(); QRectF r(pos.x() + line.x.toReal(), pos.y() + line.y.toReal(), - lineHeight / 2, QFontMetrics(eng->font()).width(QLatin1Char(' '))); + lineHeight / 2, QFontMetrics(eng->font()).horizontalAdvance(QLatin1Char(' '))); setPenAndDrawBackground(p, QPen(), selection->format, r); p->setPen(pen); } @@ -2540,7 +2540,7 @@ void QTextLine::draw(QPainter *p, const QPointF &pos, const QTextLayout::FormatR QPainterPrivate::get(p)->drawTextItem(QPointF(iterator.x.toReal(), y.toReal()), gf, eng); if (eng->option.flags() & QTextOption::ShowTabsAndSpaces) { QChar visualTab(0x2192); - int w = QFontMetrics(f).width(visualTab); + int w = QFontMetrics(f).horizontalAdvance(visualTab); qreal x = iterator.itemWidth.toReal() - w; // Right-aligned if (x < 0) p->setClipRect(QRectF(iterator.x.toReal(), line.y.toReal(), diff --git a/src/gui/text/qtextlayout.h b/src/gui/text/qtextlayout.h index 980a099b05..67bc75a6b8 100644 --- a/src/gui/text/qtextlayout.h +++ b/src/gui/text/qtextlayout.h @@ -69,7 +69,7 @@ class Q_GUI_EXPORT QTextInlineObject { public: QTextInlineObject(int i, QTextEngine *e) : itm(i), eng(e) {} - inline QTextInlineObject() : itm(0), eng(Q_NULLPTR) {} + inline QTextInlineObject() : itm(0), eng(nullptr) {} inline bool isValid() const { return eng; } QRectF rect() const; @@ -107,7 +107,7 @@ public: // does itemization QTextLayout(); QTextLayout(const QString& text); - QTextLayout(const QString& text, const QFont &font, QPaintDevice *paintdevice = Q_NULLPTR); + QTextLayout(const QString& text, const QFont &font, QPaintDevice *paintdevice = nullptr); QTextLayout(const QTextBlock &b); ~QTextLayout(); @@ -210,7 +210,7 @@ Q_DECLARE_TYPEINFO(QTextLayout::FormatRange, Q_RELOCATABLE_TYPE); class Q_GUI_EXPORT QTextLine { public: - inline QTextLine() : index(0), eng(Q_NULLPTR) {} + inline QTextLine() : index(0), eng(nullptr) {} inline bool isValid() const { return eng; } QRectF rect() const; @@ -255,7 +255,7 @@ public: int lineNumber() const { return index; } - void draw(QPainter *p, const QPointF &point, const QTextLayout::FormatRange *selection = Q_NULLPTR) const; + void draw(QPainter *p, const QPointF &point, const QTextLayout::FormatRange *selection = nullptr) const; #if !defined(QT_NO_RAWFONT) QList<QGlyphRun> glyphRuns(int from = -1, int length = -1) const; diff --git a/src/gui/text/qtextobject.h b/src/gui/text/qtextobject.h index a5030de112..7e4efa28f8 100644 --- a/src/gui/text/qtextobject.h +++ b/src/gui/text/qtextobject.h @@ -203,7 +203,7 @@ class Q_GUI_EXPORT QTextBlock friend class QSyntaxHighlighter; public: inline QTextBlock(QTextDocumentPrivate *priv, int b) : p(priv), n(b) {} - inline QTextBlock() : p(Q_NULLPTR), n(0) {} + inline QTextBlock() : p(nullptr), n(0) {} inline QTextBlock(const QTextBlock &o) : p(o.p), n(o.n) {} inline QTextBlock &operator=(const QTextBlock &o) { p = o.p; n = o.n; return *this; } @@ -260,7 +260,7 @@ public: friend class QTextBlock; iterator(const QTextDocumentPrivate *priv, int begin, int end, int f) : p(priv), b(begin), e(end), n(f) {} public: - iterator() : p(Q_NULLPTR), b(0), e(0), n(0) {} + iterator() : p(nullptr), b(0), e(0), n(0) {} #if QT_VERSION < QT_VERSION_CHECK(6,0,0) iterator(const iterator &o) : p(o.p), b(o.b), e(o.e), n(o.n) {} #endif @@ -304,7 +304,7 @@ class Q_GUI_EXPORT QTextFragment { public: inline QTextFragment(const QTextDocumentPrivate *priv, int f, int fe) : p(priv), n(f), ne(fe) {} - inline QTextFragment() : p(Q_NULLPTR), n(0), ne(0) {} + inline QTextFragment() : p(nullptr), n(0), ne(0) {} inline QTextFragment(const QTextFragment &o) : p(o.p), n(o.n), ne(o.ne) {} inline QTextFragment &operator=(const QTextFragment &o) { p = o.p; n = o.n; ne = o.ne; return *this; } diff --git a/src/gui/text/qtextodfwriter.cpp b/src/gui/text/qtextodfwriter.cpp index 3dd19a6eda..30f5bc1051 100644 --- a/src/gui/text/qtextodfwriter.cpp +++ b/src/gui/text/qtextodfwriter.cpp @@ -94,7 +94,7 @@ public: if (contentStream) contentStream->close(); } - virtual void addFile(const QString &, const QString &, const QByteArray &) Q_DECL_OVERRIDE + virtual void addFile(const QString &, const QString &, const QByteArray &) override { // we ignore this... } @@ -137,7 +137,7 @@ public: zip.close(); } - virtual void addFile(const QString &fileName, const QString &mimeType, const QByteArray &bytes) Q_DECL_OVERRIDE + virtual void addFile(const QString &fileName, const QString &mimeType, const QByteArray &bytes) override { zip.addFile(fileName, bytes); addFile(fileName, mimeType); diff --git a/src/gui/text/qtextoption.cpp b/src/gui/text/qtextoption.cpp index 2a16f50f33..310ced5463 100644 --- a/src/gui/text/qtextoption.cpp +++ b/src/gui/text/qtextoption.cpp @@ -404,24 +404,24 @@ QList<QTextOption::Tab> QTextOption::tabs() const */ /*! - \variable Tab::type + \variable QTextOption::Tab::type Determine which type is used. In a paragraph that has layoutDirection() RightToLeft the type LeftTab will be interpreted to be a RightTab and vice versa. */ /*! - \variable Tab::delimiter + \variable QTextOption::Tab::delimiter If type is DelimitorTab; tab until this char is found in the text. */ /*! - \fn Tab::Tab() + \fn QTextOption::Tab::Tab() Creates a default left tab with position 80. */ /*! - \fn Tab::Tab(qreal pos, TabType tabType, QChar delim = QChar()) + \fn QTextOption::Tab::Tab(qreal pos, TabType tabType, QChar delim = QChar()) Creates a tab with the given position, tab type, and delimiter (\a pos, \a tabType, \a delim). @@ -432,27 +432,20 @@ QList<QTextOption::Tab> QTextOption::tabs() const */ /*! - \fn bool Tab::operator==(const Tab &other) const + \fn bool QTextOption::Tab::operator==(const QTextOption::Tab &other) const Returns \c true if tab \a other is equal to this tab; otherwise returns \c false. */ /*! - \fn bool Tab::operator!=(const Tab &other) const + \fn bool QTextOption::Tab::operator!=(const QTextOption::Tab &other) const Returns \c true if tab \a other is not equal to this tab; otherwise returns \c false. */ /*! - \fn void setTabs(const QList<Tab> &tabStops) - Set the Tab properties to \a tabStops. - - \sa tabStopDistance(), tabs() -*/ - -/*! \since 4.4 \fn QList<QTextOption::Tab> QTextOption::tabs() const Returns a list of tab positions defined for the text layout. diff --git a/src/gui/text/qtexttable.h b/src/gui/text/qtexttable.h index ee8e974396..156b091b05 100644 --- a/src/gui/text/qtexttable.h +++ b/src/gui/text/qtexttable.h @@ -54,7 +54,7 @@ class QTextTablePrivate; class Q_GUI_EXPORT QTextTableCell { public: - QTextTableCell() : table(Q_NULLPTR) {} + QTextTableCell() : table(nullptr) {} ~QTextTableCell() {} QTextTableCell(const QTextTableCell &o) : table(o.table), fragment(o.fragment) {} QTextTableCell &operator=(const QTextTableCell &o) @@ -69,7 +69,7 @@ public: int rowSpan() const; int columnSpan() const; - inline bool isValid() const { return table != Q_NULLPTR; } + inline bool isValid() const { return table != nullptr; } QTextCursor firstCursorPosition() const; QTextCursor lastCursorPosition() const; diff --git a/src/gui/text/qtexttable_p.h b/src/gui/text/qtexttable_p.h index 848537272d..c969e1d5bc 100644 --- a/src/gui/text/qtexttable_p.h +++ b/src/gui/text/qtexttable_p.h @@ -65,8 +65,8 @@ public: ~QTextTablePrivate(); static QTextTable *createTable(QTextDocumentPrivate *, int pos, int rows, int cols, const QTextTableFormat &tableFormat); - void fragmentAdded(QChar type, uint fragment) Q_DECL_OVERRIDE; - void fragmentRemoved(QChar type, uint fragment) Q_DECL_OVERRIDE; + void fragmentAdded(QChar type, uint fragment) override; + void fragmentRemoved(QChar type, uint fragment) override; void update() const; |