diff options
Diffstat (limited to 'src/gui/text')
36 files changed, 612 insertions, 405 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/qdistancefield.cpp b/src/gui/text/qdistancefield.cpp index 4b5d4a48b6..e7ca00b3a9 100644 --- a/src/gui/text/qdistancefield.cpp +++ b/src/gui/text/qdistancefield.cpp @@ -436,7 +436,7 @@ static void drawPolygons(qint32 *bits, int width, int height, const QPoint *vert const quint32 *indices, int indexCount, qint32 value) { Q_ASSERT(indexCount != 0); - typedef QVarLengthArray<quint8, 16> ScanLine; + typedef QVarLengthArray<quint16, 16> ScanLine; QVarLengthArray<ScanLine, 128> scans(height); int first = 0; for (int i = 1; i < indexCount; ++i) { @@ -461,16 +461,16 @@ static void drawPolygons(qint32 *bits, int width, int height, const QPoint *vert for (int y = fromY; y < toY; ++y) { quint32 c = quint32(x >> 8); if (c < quint32(width)) - scans[y].append(quint8(c)); + scans[y].append(quint16(c)); x += dx; } } for (int i = 0; i < height; ++i) { - quint8 *scanline = scans[i].data(); + quint16 *scanline = scans[i].data(); int size = scans[i].size(); for (int j = 1; j < size; ++j) { int k = j; - quint8 value = scanline[k]; + quint16 value = scanline[k]; for (; k != 0 && value < scanline[k - 1]; --k) scanline[k] = scanline[k - 1]; scanline[k] = value; @@ -478,7 +478,7 @@ static void drawPolygons(qint32 *bits, int width, int height, const QPoint *vert qint32 *line = bits + i * width; int j = 0; for (; j + 1 < size; j += 2) { - for (quint8 x = scanline[j]; x < scanline[j + 1]; ++x) + for (quint16 x = scanline[j]; x < scanline[j + 1]; ++x) line[x] = value; } if (j < size) { @@ -516,7 +516,7 @@ static void makeDistanceField(QDistanceFieldData *data, const QPainterPath &path for (int i = 0; i < imgWidth * imgHeight; ++i) bits[i] = exteriorColor; - const qreal angleStep = qreal(15 * 3.141592653589793238 / 180); + const qreal angleStep = qDegreesToRadians(qreal(15)); const QPoint rotation(qRound(qCos(angleStep) * 0x4000), qRound(qSin(angleStep) * 0x4000)); // 2:14 signed diff --git a/src/gui/text/qfont.cpp b/src/gui/text/qfont.cpp index 806ede88e2..220e89a0c4 100644 --- a/src/gui/text/qfont.cpp +++ b/src/gui/text/qfont.cpp @@ -1324,6 +1324,11 @@ QFont::StyleHint QFont::styleHint() const looking font that contains the character. The NoFontMerging flag disables this feature. Please note that enabling this flag will not prevent Qt from automatically picking a suitable font when the selected font does not support the writing system of the text. + \value PreferNoShaping Sometimes, a font will apply complex rules to a set of characters in + order to display them correctly. In some writing systems, such as Brahmic scripts, this is + required in order for the text to be legible, but in e.g. Latin script, it is merely + a cosmetic feature. The PreferNoShaping flag will disable all such features when they + are not required, which will improve performance in most cases. Any of these may be OR-ed with one of these flags: @@ -2844,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 @@ -2867,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.h b/src/gui/text/qfont.h index 6f0dd27fbe..9c250c82c3 100644 --- a/src/gui/text/qfont.h +++ b/src/gui/text/qfont.h @@ -68,6 +68,7 @@ public: Monospace, Fantasy }; + Q_ENUM(StyleHint) enum StyleStrategy { PreferDefault = 0x0001, @@ -82,6 +83,7 @@ public: OpenGLCompatible = 0x0200, ForceIntegerMetrics = 0x0400, NoSubpixelAntialias = 0x0800, + PreferNoShaping = 0x1000, NoFontMerging = 0x8000 }; Q_ENUM(StyleStrategy) @@ -92,6 +94,7 @@ public: PreferVerticalHinting = 2, PreferFullHinting = 3 }; + Q_ENUM(HintingPreference) // Mapping OpenType weight value. enum Weight { @@ -105,12 +108,14 @@ public: ExtraBold = 81, // 800 Black = 87 // 900 }; + Q_ENUM(Weight) enum Style { StyleNormal, StyleItalic, StyleOblique }; + Q_ENUM(Style) enum Stretch { AnyStretch = 0, @@ -124,6 +129,7 @@ public: ExtraExpanded = 150, UltraExpanded = 200 }; + Q_ENUM(Stretch) enum Capitalization { MixedCase, @@ -132,11 +138,13 @@ public: SmallCaps, Capitalize }; + Q_ENUM(Capitalization) enum SpacingType { PercentageSpacing, AbsoluteSpacing }; + Q_ENUM(SpacingType) enum ResolveProperties { FamilyResolved = 0x0001, 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..404a722e29 100644 --- a/src/gui/text/qfontdatabase.cpp +++ b/src/gui/text/qfontdatabase.cpp @@ -74,6 +74,7 @@ # define FM_DEBUG if (false) qDebug #endif +#include <qtgui_tracepoints_p.h> QT_BEGIN_NAMESPACE @@ -804,6 +805,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); @@ -1002,6 +1010,8 @@ QFontEngine *loadEngine(int script, const QFontDef &request, QFontEngine *engine = loadSingleEngine(script, request, family, foundry, style, size); if (engine && !(request.styleStrategy & QFont::NoFontMerging) && !engine->symbol) { + Q_TRACE(qfontdatabase_loadengine, request.family, request.pointSize); + QPlatformFontDatabase *pfdb = QGuiApplicationPrivate::platformIntegration()->fontDatabase(); QFontEngineMulti *pfMultiEngine = pfdb->fontEngineMulti(engine, QChar::Script(script)); if (!request.fallBackFamilies.isEmpty()) { @@ -2432,6 +2442,8 @@ int QFontDatabasePrivate::addAppFont(const QByteArray &fontData, const QString & font.data = fontData; font.fileName = fileName; + Q_TRACE(qfontdatabaseprivate_addappfont, fileName); + int i; for (i = 0; i < applicationFonts.count(); ++i) if (applicationFonts.at(i).families.isEmpty()) @@ -2487,6 +2499,9 @@ int QFontDatabase::addApplicationFont(const QString &fileName) QFile f(fileName); if (!f.open(QIODevice::ReadOnly)) return -1; + + Q_TRACE(qfontdatabase_addapplicationfont, fileName); + data = f.readAll(); } QMutexLocker locker(fontDatabaseMutex()); @@ -2685,7 +2700,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 +2798,9 @@ void QFontDatabase::load(const QFontPrivate *d, int script) if (d->engineData->engines[script]) return; - QFontEngine *fe = Q_NULLPTR; + QFontEngine *fe = nullptr; + + Q_TRACE(qfontdatabase_load, req.family, req.pointSize); req.fallBackFamilies = fallBackFamilies; if (!req.fallBackFamilies.isEmpty()) diff --git a/src/gui/text/qfontengine.cpp b/src/gui/text/qfontengine.cpp index 29c48da7be..3b64ee0136 100644 --- a/src/gui/text/qfontengine.cpp +++ b/src/gui/text/qfontengine.cpp @@ -359,10 +359,8 @@ bool QFontEngine::supportsScript(QChar::Script script) const // ### TODO: This only works for scripts that require OpenType. More generally // for scripts that do not require OpenType we should just look at the list of // supported writing systems in the font's OS/2 table. - if (!((script >= QChar::Script_Syriac && script <= QChar::Script_Sinhala) - || script == QChar::Script_Khmer || script == QChar::Script_Nko)) { + if (!scriptRequiresOpenType(script)) return true; - } #if QT_CONFIG(harfbuzz) if (qt_useHarfbuzzNG()) { @@ -994,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(); @@ -1082,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(); @@ -1090,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) @@ -1236,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 514e9424b2..a411e9ce4c 100644 --- a/src/gui/text/qfontengine_p.h +++ b/src/gui/text/qfontengine_p.h @@ -242,6 +242,12 @@ public: void *harfbuzzFace() const; bool supportsScript(QChar::Script script) const; + inline static bool scriptRequiresOpenType(QChar::Script script) + { + return ((script >= QChar::Script_Syriac && script <= QChar::Script_Sinhala) + || script == QChar::Script_Khmer || script == QChar::Script_Nko); + } + virtual int getPointInOutline(glyph_t glyph, int flags, quint32 point, QFixed *xpos, QFixed *ypos, quint32 *nPoints); void clearGlyphCache(const void *key); @@ -405,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; } @@ -443,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 8067969f56..407559ad51 100644 --- a/src/gui/text/qfontmetrics.cpp +++ b/src/gui/text/qfontmetrics.cpp @@ -452,7 +452,7 @@ bool QFontMetrics::inFontUcs4(uint ucs4) const value is negative if the pixels of the character extend to the left of the logical origin. - See width(QChar) for a graphical description of this metric. + See width() for a graphical description of this metric. \sa rightBearing(), minLeftBearing(), width() */ @@ -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,16 +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_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); @@ -554,9 +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); } /*! @@ -575,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 @@ -585,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; @@ -675,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. @@ -709,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() */ @@ -844,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. @@ -1335,7 +1402,7 @@ bool QFontMetricsF::inFontUcs4(uint ucs4) const value is negative if the pixels of the character extend to the left of the logical origin. - See width(QChar) for a graphical description of this metric. + See width() for a graphical description of this metric. \sa rightBearing(), minLeftBearing(), width() */ @@ -1394,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. @@ -1402,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(); } /*! @@ -1419,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. @@ -1436,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.; @@ -1465,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 @@ -1475,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. @@ -1648,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/qfontsubset.cpp b/src/gui/text/qfontsubset.cpp index 92eeaf7919..f5fc562e13 100644 --- a/src/gui/text/qfontsubset.cpp +++ b/src/gui/text/qfontsubset.cpp @@ -136,7 +136,7 @@ QByteArray QFontSubset::widthArray() const QByteArray width; QPdf::ByteStream s(&width); - QFixed scale = QFixed(1000)/emSquare; + const qreal scale = 1000.0/emSquare.toInt(); QFixed defWidth = widths[0]; //qDebug("defWidth=%d, scale=%f", defWidth.toInt(), scale.toReal()); @@ -145,7 +145,7 @@ QByteArray QFontSubset::widthArray() const defWidth = 0; } if (defWidth > 0) { - s << "/DW " << (defWidth*scale).toInt(); + s << "/DW " << qRound(defWidth.toInt() * scale); } else { s << "/W ["; for (int g = 0; g < nGlyphs();) { @@ -174,11 +174,11 @@ QByteArray QFontSubset::widthArray() const if (endnonlinear > start) { s << start << '['; for (int i = start; i < endnonlinear; ++i) - s << (widths[i]*scale).toInt(); + s << qRound(widths[i].toInt() * scale); s << "]\n"; } if (startLinear) - s << startLinear << g - 1 << (widths[startLinear]*scale).toInt() << '\n'; + s << startLinear << g - 1 << qRound(widths[startLinear].toInt() * scale) << '\n'; } s << "]\n"; } 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.h b/src/gui/text/qstatictext.h index 00dfccc144..e6a196d865 100644 --- a/src/gui/text/qstatictext.h +++ b/src/gui/text/qstatictext.h @@ -62,7 +62,7 @@ public: }; QStaticText(); - QStaticText(const QString &text); + explicit QStaticText(const QString &text); QStaticText(const QStaticText &other); #ifdef Q_COMPILER_RVALUE_REFS QStaticText &operator=(QStaticText &&other) Q_DECL_NOTHROW { swap(other); return *this; } 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 f8215f92e9..d95932f4db 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -71,19 +71,8 @@ QT_BEGIN_NAMESPACE -Q_CORE_EXPORT unsigned int qt_int_sqrt(unsigned int n); +Q_CORE_EXPORT Q_DECL_CONST_FUNCTION unsigned int qt_int_sqrt(unsigned int n); -/*! - Returns \c true if the string \a text is likely to be rich text; - otherwise returns \c false. - - This function uses a fast and therefore simple heuristic. It - mainly checks whether there is something that looks like a tag - before the first line break. Although the result may be correct - for common cases, there is no guarantee. - - This function is defined in the \c <QTextDocument> header file. -*/ bool Qt::mightBeRichText(const QString& text) { if (text.isEmpty()) @@ -142,17 +131,6 @@ bool Qt::mightBeRichText(const QString& text) return false; } - -/*! - Converts the plain text string \a plain to an HTML-formatted - paragraph while preserving most of its look. - - \a mode defines how whitespace is handled. - - This function is defined in the \c <QTextDocument> header file. - - \sa escape(), mightBeRichText() -*/ QString Qt::convertFromPlainText(const QString &plain, Qt::WhiteSpaceMode mode) { int col = 0; @@ -202,11 +180,6 @@ QString Qt::convertFromPlainText(const QString &plain, Qt::WhiteSpaceMode mode) } #ifndef QT_NO_TEXTCODEC -/*! - \internal - - This function is defined in the \c <QTextDocument> header file. -*/ QTextCodec *Qt::codecForHtml(const QByteArray &ba) { return QTextCodec::codecForHtml(ba); @@ -805,7 +778,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 +943,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 +955,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 +972,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 +981,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 +1814,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 +1871,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..c847d3ce88 100644 --- a/src/gui/text/qtextdocument.h +++ b/src/gui/text/qtextdocument.h @@ -70,6 +70,7 @@ class QTextCursor; template<typename T> class QVector; +#ifndef Q_CLANG_QDOC namespace Qt { Q_GUI_EXPORT bool mightBeRichText(const QString&); @@ -79,6 +80,7 @@ namespace Qt Q_GUI_EXPORT QTextCodec *codecForHtml(const QByteArray &ba); #endif } +#endif class Q_GUI_EXPORT QAbstractUndoItem { @@ -116,11 +118,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/qtextdocument_p.cpp b/src/gui/text/qtextdocument_p.cpp index 7341fa8e83..66e038122c 100644 --- a/src/gui/text/qtextdocument_p.cpp +++ b/src/gui/text/qtextdocument_p.cpp @@ -203,7 +203,7 @@ QTextDocumentPrivate::QTextDocumentPrivate() inContentsChange = false; blockCursorAdjustment = false; - defaultTextOption.setTabStop(80); // same as in qtextengine.cpp + defaultTextOption.setTabStopDistance(80); // same as in qtextengine.cpp defaultTextOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); defaultCursorMoveStyle = Qt::LogicalMoveStyle; 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 4d24fb50af..c88daed8d8 100644 --- a/src/gui/text/qtextengine.cpp +++ b/src/gui/text/qtextengine.cpp @@ -1005,20 +1005,53 @@ void QTextEngine::shapeText(int item) const QFontEngine *fontEngine = this->fontEngine(si, &si.ascent, &si.descent, &si.leading); + bool kerningEnabled; + bool letterSpacingIsAbsolute; + bool shapingEnabled; + QFixed letterSpacing, wordSpacing; +#ifndef QT_NO_RAWFONT + if (useRawFont) { + QTextCharFormat f = format(&si); + kerningEnabled = f.fontKerning(); + shapingEnabled = QFontEngine::scriptRequiresOpenType(QChar::Script(si.analysis.script)) + || (f.fontStyleStrategy() & QFont::PreferNoShaping) == 0; + wordSpacing = QFixed::fromReal(f.fontWordSpacing()); + letterSpacing = QFixed::fromReal(f.fontLetterSpacing()); + letterSpacingIsAbsolute = true; + } else +#endif + { + QFont font = this->font(si); + kerningEnabled = font.d->kerning; + shapingEnabled = QFontEngine::scriptRequiresOpenType(QChar::Script(si.analysis.script)) + || (font.d->request.styleStrategy & QFont::PreferNoShaping) == 0; + letterSpacingIsAbsolute = font.d->letterSpacingIsAbsolute; + letterSpacing = font.d->letterSpacing; + wordSpacing = font.d->wordSpacing; + + if (letterSpacingIsAbsolute && letterSpacing.value()) + letterSpacing *= font.d->dpi / qt_defaultDpiY(); + } + // split up the item into parts that come from different font engines // k * 3 entries, array[k] == index in string, array[k + 1] == index in glyphs, array[k + 2] == engine index QVector<uint> itemBoundaries; itemBoundaries.reserve(24); - if (fontEngine->type() == QFontEngine::Multi) { + + QGlyphLayout initialGlyphs = availableGlyphs(&si); + int nGlyphs = initialGlyphs.numGlyphs; + if (fontEngine->type() == QFontEngine::Multi || !shapingEnabled) { // ask the font engine to find out which glyphs (as an index in the specific font) // to use for the text in one item. - QGlyphLayout initialGlyphs = availableGlyphs(&si); - - int nGlyphs = initialGlyphs.numGlyphs; - QFontEngine::ShaperFlags shaperFlags(QFontEngine::GlyphIndicesOnly); + QFontEngine::ShaperFlags shaperFlags = + shapingEnabled + ? QFontEngine::GlyphIndicesOnly + : QFontEngine::ShaperFlag(0); if (!fontEngine->stringToCMap(reinterpret_cast<const QChar *>(string), itemLength, &initialGlyphs, &nGlyphs, shaperFlags)) Q_UNREACHABLE(); + } + if (fontEngine->type() == QFontEngine::Multi) { uint lastEngine = ~0u; for (int i = 0, glyph_pos = 0; i < itemLength; ++i, ++glyph_pos) { const uint engineIdx = initialGlyphs.glyphs[glyph_pos] >> 24; @@ -1046,35 +1079,29 @@ void QTextEngine::shapeText(int item) const itemBoundaries.append(0); } - bool kerningEnabled; - bool letterSpacingIsAbsolute; - QFixed letterSpacing, wordSpacing; -#ifndef QT_NO_RAWFONT - if (useRawFont) { - QTextCharFormat f = format(&si); - kerningEnabled = f.fontKerning(); - wordSpacing = QFixed::fromReal(f.fontWordSpacing()); - letterSpacing = QFixed::fromReal(f.fontLetterSpacing()); - letterSpacingIsAbsolute = true; - } else -#endif - { - QFont font = this->font(si); - kerningEnabled = font.d->kerning; - letterSpacingIsAbsolute = font.d->letterSpacingIsAbsolute; - letterSpacing = font.d->letterSpacing; - wordSpacing = font.d->wordSpacing; + if (Q_UNLIKELY(!shapingEnabled)) { + ushort *log_clusters = logClusters(&si); - if (letterSpacingIsAbsolute && letterSpacing.value()) - letterSpacing *= font.d->dpi / qt_defaultDpiY(); - } + int glyph_pos = 0; + for (int i = 0; i < itemLength; ++i, ++glyph_pos) { + log_clusters[i] = glyph_pos; + initialGlyphs.attributes[glyph_pos].clusterStart = true; + if (QChar::isHighSurrogate(string[i]) + && i + 1 < itemLength + && QChar::isLowSurrogate(string[i + 1])) { + ++i; + log_clusters[i] = glyph_pos; + } + } + si.num_glyphs = glyph_pos; #if QT_CONFIG(harfbuzz) - if (Q_LIKELY(qt_useHarfbuzzNG())) + } else if (Q_LIKELY(qt_useHarfbuzzNG())) { si.num_glyphs = shapeTextWithHarfbuzzNG(si, string, itemLength, fontEngine, itemBoundaries, kerningEnabled, letterSpacing != 0); - else #endif - si.num_glyphs = shapeTextWithHarfbuzz(si, string, itemLength, fontEngine, itemBoundaries, kerningEnabled); + } else { + si.num_glyphs = shapeTextWithHarfbuzz(si, string, itemLength, fontEngine, itemBoundaries, kerningEnabled); + } if (Q_UNLIKELY(si.num_glyphs == 0)) { Q_UNREACHABLE(); // ### report shaping errors somehow return; @@ -1215,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 @@ -1225,7 +1252,7 @@ int QTextEngine::shapeTextWithHarfbuzzNG(const QScriptItem &si, "graphite2", "ot", "fallback", - Q_NULLPTR + nullptr }; shaper_list = s_shaper_list_without_coretext; } @@ -3016,7 +3043,7 @@ QFixed QTextEngine::calculateTabWidth(int item, QFixed x) const } } } - QFixed tab = QFixed::fromReal(option.tabStop()); + QFixed tab = QFixed::fromReal(option.tabStopDistance()); if (tab <= 0) tab = 80; // default tab *= dpiScale; @@ -3483,19 +3510,31 @@ QStackTextEngine::QStackTextEngine(const QString &string, const QFont &f) } QTextItemInt::QTextItemInt(const QScriptItem &si, QFont *font, const QTextCharFormat &format) - : justified(false), underlineStyle(QTextCharFormat::NoUnderline), charFormat(format), - num_chars(0), chars(0), logClusters(0), f(0), fontEngine(0) + : justified(false), + underlineStyle(QTextCharFormat::NoUnderline), + charFormat(format), + num_chars(0), + chars(nullptr), + logClusters(nullptr), + f(font), + fontEngine(font->d->engineForScript(si.analysis.script)) { - f = font; - fontEngine = f->d->engineForScript(si.analysis.script); Q_ASSERT(fontEngine); initWithScriptItem(si); } QTextItemInt::QTextItemInt(const QGlyphLayout &g, QFont *font, const QChar *chars_, int numChars, QFontEngine *fe, const QTextCharFormat &format) - : flags(0), justified(false), underlineStyle(QTextCharFormat::NoUnderline), charFormat(format), - num_chars(numChars), chars(chars_), logClusters(0), f(font), glyphs(g), fontEngine(fe) + : flags(0), + justified(false), + underlineStyle(QTextCharFormat::NoUnderline), + charFormat(format), + num_chars(numChars), + chars(chars_), + logClusters(nullptr), + f(font), + glyphs(g), + fontEngine(fe) { } diff --git a/src/gui/text/qtextengine_p.h b/src/gui/text/qtextengine_p.h index 58ddc7c06d..90c1a12acd 100644 --- a/src/gui/text/qtextengine_p.h +++ b/src/gui/text/qtextengine_p.h @@ -323,13 +323,9 @@ public: QFontEngine *fontEngine; }; -struct Q_AUTOTEST_EXPORT QScriptItem +struct QScriptItem { - inline QScriptItem() - : position(0), - num_glyphs(0), descent(-1), ascent(-1), leading(-1), width(-1), - glyph_data_offset(0) {} - inline QScriptItem(int p, const QScriptAnalysis &a) + Q_DECL_CONSTEXPR QScriptItem(int p, QScriptAnalysis a) Q_DECL_NOTHROW : position(p), analysis(a), num_glyphs(0), descent(-1), ascent(-1), leading(-1), width(-1), glyph_data_offset(0) {} @@ -342,11 +338,12 @@ struct Q_AUTOTEST_EXPORT QScriptItem QFixed leading; QFixed width; int glyph_data_offset; - QFixed height() const { return ascent + descent; } + Q_DECL_CONSTEXPR QFixed height() const Q_DECL_NOTHROW { return ascent + descent; } +private: + friend class QVector<QScriptItem>; + QScriptItem() {}; // for QVector, don't use }; - - -Q_DECLARE_TYPEINFO(QScriptItem, Q_MOVABLE_TYPE); +Q_DECLARE_TYPEINFO(QScriptItem, Q_PRIMITIVE_TYPE); typedef QVector<QScriptItem> QScriptItemArray; diff --git a/src/gui/text/qtextformat.cpp b/src/gui/text/qtextformat.cpp index 36e0a77bd0..08106db6ce 100644 --- a/src/gui/text/qtextformat.cpp +++ b/src/gui/text/qtextformat.cpp @@ -164,24 +164,25 @@ QDataStream &operator>>(QDataStream &stream, QTextLength &length) } #endif // QT_NO_DATASTREAM -class QTextFormatPrivate : public QSharedData +namespace { +struct Property { -public: - QTextFormatPrivate() : hashDirty(true), fontDirty(true), hashValue(0) {} + inline Property(qint32 k, const QVariant &v) : key(k), value(v) {} + inline Property() {} - struct Property - { - inline Property(qint32 k, const QVariant &v) : key(k), value(v) {} - inline Property() {} + qint32 key = -1; + QVariant value; - qint32 key; - QVariant value; + inline bool operator==(const Property &other) const + { return key == other.key && value == other.value; } +}; +} +Q_DECLARE_TYPEINFO(Property, Q_MOVABLE_TYPE); - inline bool operator==(const Property &other) const - { return key == other.key && value == other.value; } - inline bool operator!=(const Property &other) const - { return key != other.key || value != other.value; } - }; +class QTextFormatPrivate : public QSharedData +{ +public: + QTextFormatPrivate() : hashDirty(true), fontDirty(true), hashValue(0) {} inline uint hash() const { @@ -200,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; @@ -215,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; } @@ -263,7 +268,6 @@ private: friend QDataStream &operator<<(QDataStream &, const QTextFormat &); friend QDataStream &operator>>(QDataStream &, QTextFormat &); }; -Q_DECLARE_TYPEINFO(QTextFormatPrivate::Property, Q_MOVABLE_TYPE); static inline uint hash(const QColor &color) { @@ -845,10 +849,10 @@ void QTextFormat::merge(const QTextFormat &other) QTextFormatPrivate *d = this->d; - const QVector<QTextFormatPrivate::Property> &otherProps = other.d->props; + const QVector<QT_PREPEND_NAMESPACE(Property)> &otherProps = other.d->props; d->props.reserve(d->props.size() + otherProps.size()); for (int i = 0; i < otherProps.count(); ++i) { - const QTextFormatPrivate::Property &p = otherProps.at(i); + const QT_PREPEND_NAMESPACE(Property) &p = otherProps.at(i); d->insertProperty(p.key, p.value); } } @@ -1333,9 +1337,9 @@ bool QTextFormat::operator==(const QTextFormat &rhs) const \value DashDotLine Dashs and dots are drawn using Qt::DashDotLine. \value DashDotDotLine Underlines draw drawn using Qt::DashDotDotLine. \value WaveUnderline The text is underlined using a wave shaped line. - \value SpellCheckUnderline The underline is drawn depending on the QStyle::SH_SpellCeckUnderlineStyle - style hint of the QApplication style. By default this is mapped to - WaveUnderline, on \macos it is mapped to DashDotLine. + \value SpellCheckUnderline The underline is drawn depending on the SpellCheckUnderlineStyle + theme hint of QPlatformTheme. By default this is mapped to + WaveUnderline, on \macos it is mapped to DotLine. \sa Qt::PenStyle */ @@ -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 da4e21728f..9154182df1 100644 --- a/src/gui/text/qtexthtmlparser.cpp +++ b/src/gui/text/qtexthtmlparser.cpp @@ -493,7 +493,7 @@ static QString quoteNewline(const QString &s) QTextHtmlParserNode::QTextHtmlParserNode() : parent(0), id(Html_unknown), - cssFloat(QTextFrameFormat::InFlow), hasOwnListStyle(false), hasOwnLineHeightType(false), + cssFloat(QTextFrameFormat::InFlow), hasOwnListStyle(false), hasOwnLineHeightType(false), hasLineHeightMultiplier(false), hasCssListIndent(false), isEmptyParagraph(false), isTextFrame(false), isRootFrame(false), displayMode(QTextHtmlElement::DisplayInline), hasHref(false), listStyle(QTextListFormat::ListStyleUndefined), imageWidth(-1), imageHeight(-1), tableBorder(0), @@ -1216,6 +1216,11 @@ void QTextHtmlParserNode::applyCssDeclarations(const QVector<QCss::Declaration> else lineHeightType = QTextBlockFormat::SingleHeight; + if (hasLineHeightMultiplier) { + qreal lineHeight = blockFormat.lineHeight() / 100.0; + blockFormat.setProperty(QTextBlockFormat::LineHeight, lineHeight); + } + blockFormat.setProperty(QTextBlockFormat::LineHeightType, lineHeightType); hasOwnLineHeightType = true; } @@ -1227,9 +1232,14 @@ void QTextHtmlParserNode::applyCssDeclarations(const QVector<QCss::Declaration> lineHeightType = QTextBlockFormat::MinimumHeight; } else { bool ok; - QString value = decl.d->values.first().toString(); + QCss::Value cssValue = decl.d->values.first(); + QString value = cssValue.toString(); lineHeight = value.toDouble(&ok); if (ok) { + if (!hasOwnLineHeightType && cssValue.type == QCss::Value::Number) { + lineHeight *= 100.0; + hasLineHeightMultiplier = true; + } lineHeightType = QTextBlockFormat::ProportionalHeight; } else { lineHeight = 0.0; @@ -1698,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/qtexthtmlparser_p.h b/src/gui/text/qtexthtmlparser_p.h index 77bfa685c0..73dac38b82 100644 --- a/src/gui/text/qtexthtmlparser_p.h +++ b/src/gui/text/qtexthtmlparser_p.h @@ -173,6 +173,7 @@ struct QTextHtmlParserNode { uint cssFloat : 2; uint hasOwnListStyle : 1; uint hasOwnLineHeightType : 1; + uint hasLineHeightMultiplier : 1; uint hasCssListIndent : 1; uint isEmptyParagraph : 1; uint isTextFrame : 1; 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 cc91c107f9..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 @@ -167,7 +167,7 @@ QRectF QTextInlineObject::rect() const */ qreal QTextInlineObject::width() const { - return eng->layoutData->items[itm].width.toReal(); + return eng->layoutData->items.at(itm).width.toReal(); } /*! @@ -177,7 +177,7 @@ qreal QTextInlineObject::width() const */ qreal QTextInlineObject::ascent() const { - return eng->layoutData->items[itm].ascent.toReal(); + return eng->layoutData->items.at(itm).ascent.toReal(); } /*! @@ -187,7 +187,7 @@ qreal QTextInlineObject::ascent() const */ qreal QTextInlineObject::descent() const { - return eng->layoutData->items[itm].descent.toReal(); + return eng->layoutData->items.at(itm).descent.toReal(); } /*! @@ -198,7 +198,7 @@ qreal QTextInlineObject::descent() const */ qreal QTextInlineObject::height() const { - return eng->layoutData->items[itm].height().toReal(); + return eng->layoutData->items.at(itm).height().toReal(); } /*! @@ -924,7 +924,7 @@ QRectF QTextLayout::boundingRect() const QFixed ymin = d->lines.at(0).y; for (int i = 0; i < d->lines.size(); ++i) { - const QScriptLine &si = d->lines[i]; + const QScriptLine &si = d->lines.at(i); xmin = qMin(xmin, si.x); ymin = qMin(ymin, si.y); QFixed lineWidth = si.width < QFIXED_MAX ? qMax(si.width, si.textWidth) : si.textWidth; @@ -1052,9 +1052,9 @@ QList<QGlyphRun> QTextLayout::glyphRuns(int from, int length) const QHash<QPair<QFontEngine *, int>, QGlyphRun> glyphRunHash; for (int i=0; i<d->lines.size(); ++i) { - if (d->lines[i].from > from + length) + if (d->lines.at(i).from > from + length) break; - else if (d->lines[i].from + d->lines[i].length >= from) { + else if (d->lines.at(i).from + d->lines[i].length >= from) { QList<QGlyphRun> glyphRuns = QTextLine(i, d).glyphRuns(from, length); for (int j = 0; j < glyphRuns.size(); j++) { @@ -1115,7 +1115,7 @@ void QTextLayout::draw(QPainter *p, const QPointF &pos, const QVector<FormatRang int lastLine = d->lines.size(); for (int i = 0; i < d->lines.size(); ++i) { QTextLine l(i, d); - const QScriptLine &sl = d->lines[i]; + const QScriptLine &sl = d->lines.at(i); if (sl.y > clipe) { lastLine = i; @@ -1137,7 +1137,7 @@ void QTextLayout::draw(QPainter *p, const QPointF &pos, const QVector<FormatRang region.setFillRule(Qt::WindingFill); for (int line = firstLine; line < lastLine; ++line) { - const QScriptLine &sl = d->lines[line]; + const QScriptLine &sl = d->lines.at(line); QTextLine tl(line, d); QRectF lineRect(tl.naturalTextRect()); @@ -1302,7 +1302,7 @@ void QTextLayout::drawCursor(QPainter *p, const QPointF &pos, int cursorPosition return; QTextLine l(line, d); - const QScriptLine &sl = d->lines[line]; + const QScriptLine &sl = d->lines.at(line); qreal x = position.x() + l.cursorToX(cursorPosition); @@ -1415,7 +1415,7 @@ void QTextLayout::drawCursor(QPainter *p, const QPointF &pos, int cursorPosition */ QRectF QTextLine::rect() const { - const QScriptLine& sl = eng->lines[index]; + const QScriptLine& sl = eng->lines.at(index); return QRectF(sl.x.toReal(), sl.y.toReal(), sl.width.toReal(), sl.height().toReal()); } @@ -1424,7 +1424,7 @@ QRectF QTextLine::rect() const */ QRectF QTextLine::naturalTextRect() const { - const QScriptLine& sl = eng->lines[index]; + const QScriptLine& sl = eng->lines.at(index); QFixed x = sl.x + eng->alignLine(sl); QFixed width = sl.textWidth; @@ -1441,7 +1441,7 @@ QRectF QTextLine::naturalTextRect() const */ qreal QTextLine::x() const { - return eng->lines[index].x.toReal(); + return eng->lines.at(index).x.toReal(); } /*! @@ -1451,7 +1451,7 @@ qreal QTextLine::x() const */ qreal QTextLine::y() const { - return eng->lines[index].y.toReal(); + return eng->lines.at(index).y.toReal(); } /*! @@ -1461,7 +1461,7 @@ qreal QTextLine::y() const */ qreal QTextLine::width() const { - return eng->lines[index].width.toReal(); + return eng->lines.at(index).width.toReal(); } @@ -1472,7 +1472,7 @@ qreal QTextLine::width() const */ qreal QTextLine::ascent() const { - return eng->lines[index].ascent.toReal(); + return eng->lines.at(index).ascent.toReal(); } /*! @@ -1482,7 +1482,7 @@ qreal QTextLine::ascent() const */ qreal QTextLine::descent() const { - return eng->lines[index].descent.toReal(); + return eng->lines.at(index).descent.toReal(); } /*! @@ -1494,7 +1494,7 @@ qreal QTextLine::descent() const */ qreal QTextLine::height() const { - return eng->lines[index].height().ceil().toReal(); + return eng->lines.at(index).height().ceil().toReal(); } /*! @@ -1506,7 +1506,7 @@ qreal QTextLine::height() const */ qreal QTextLine::leading() const { - return eng->lines[index].leading.toReal(); + return eng->lines.at(index).leading.toReal(); } /*! @@ -1541,7 +1541,7 @@ void QTextLine::setLeadingIncluded(bool included) */ bool QTextLine::leadingIncluded() const { - return eng->lines[index].leadingIncluded; + return eng->lines.at(index).leadingIncluded; } /*! @@ -1551,7 +1551,7 @@ bool QTextLine::leadingIncluded() const */ qreal QTextLine::naturalTextWidth() const { - return eng->lines[index].textWidth.toReal(); + return eng->lines.at(index).textWidth.toReal(); } /*! @@ -1566,7 +1566,7 @@ qreal QTextLine::naturalTextWidth() const */ qreal QTextLine::horizontalAdvance() const { - return eng->lines[index].textAdvance.toReal(); + return eng->lines.at(index).textAdvance.toReal(); } /*! @@ -1832,7 +1832,7 @@ void QTextLine::layout_helper(int maxGlyphs) lbh.softHyphenWidth = 0; if (newItem != item) { item = newItem; - const QScriptItem ¤t = eng->layoutData->items[item]; + const QScriptItem ¤t = eng->layoutData->items.at(item); if (!current.num_glyphs) { eng->shape(item); attributes = eng->attributes(); @@ -1850,7 +1850,7 @@ void QTextLine::layout_helper(int maxGlyphs) QFixed::fromReal(fontEngine->minRightBearing())); } } - const QScriptItem ¤t = eng->layoutData->items[item]; + const QScriptItem ¤t = eng->layoutData->items.at(item); lbh.tmpData.leading = qMax(lbh.tmpData.leading + lbh.tmpData.ascent, current.leading + current.ascent) - qMax(lbh.tmpData.ascent, @@ -2093,7 +2093,7 @@ void QTextLine::setPosition(const QPointF &pos) */ QPointF QTextLine::position() const { - return QPointF(eng->lines[index].x.toReal(), eng->lines[index].y.toReal()); + return QPointF(eng->lines.at(index).x.toReal(), eng->lines.at(index).y.toReal()); } // ### DOC: I have no idea what this means/does. @@ -2109,7 +2109,7 @@ QPointF QTextLine::position() const */ int QTextLine::textStart() const { - return eng->lines[index].from; + return eng->lines.at(index).from; } /*! @@ -2121,9 +2121,9 @@ int QTextLine::textLength() const { if (eng->option.flags() & QTextOption::ShowLineAndParagraphSeparators && eng->block.isValid() && index == eng->lines.count()-1) { - return eng->lines[index].length - 1; + return eng->lines.at(index).length - 1; } - return eng->lines[index].length + eng->lines[index].trailingSpaces; + return eng->lines.at(index).length + eng->lines.at(index).trailingSpaces; } static void setPenAndDrawBackground(QPainter *p, const QPen &defaultPen, const QTextCharFormat &chf, const QRectF &r) @@ -2247,7 +2247,7 @@ static QGlyphRun glyphRunWithInfo(QFontEngine *fontEngine, */ QList<QGlyphRun> QTextLine::glyphRuns(int from, int length) const { - const QScriptLine &line = eng->lines[index]; + const QScriptLine &line = eng->lines.at(index); if (line.length == 0) return QList<QGlyphRun>(); @@ -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 4cc2535b58..067f8473ea 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 87e31eeb2c..a3fa0e7351 100644 --- a/src/gui/text/qtextoption.cpp +++ b/src/gui/text/qtextoption.cpp @@ -144,7 +144,7 @@ QTextOption &QTextOption::operator=(const QTextOption &o) Sets the tab positions for the text layout to those specified by \a tabStops. - \sa tabArray(), setTabStop(), setTabs() + \sa tabArray(), setTabStopDistance(), setTabs() */ void QTextOption::setTabArray(const QList<qreal> &tabStops) { @@ -165,7 +165,7 @@ void QTextOption::setTabArray(const QList<qreal> &tabStops) Sets the tab positions for the text layout to those specified by \a tabStops. - \sa tabStops() + \sa tabStop() */ void QTextOption::setTabs(const QList<QTextOption::Tab> &tabStops) { @@ -332,22 +332,45 @@ QList<QTextOption::Tab> QTextOption::tabs() const \sa flags() */ +#if QT_DEPRECATED_SINCE(5, 10) /*! \fn qreal QTextOption::tabStop() const + \deprecated in Qt 5.10. Use tabStopDistance() instead. Returns the distance in device units between tab stops. Convenient function for the above method - \sa setTabStop(), tabArray(), setTabs(), tabs() + \sa setTabStopDistance(), tabArray(), setTabs(), tabs() */ /*! \fn void QTextOption::setTabStop(qreal tabStop) + \deprecated in Qt 5.10. Use setTabStopDistance() instead. Sets the default distance in device units between tab stops to the value specified by \a tabStop. - \sa tabStop(), setTabArray(), setTabs(), tabs() + \sa tabStopDistance(), setTabArray(), setTabs(), tabs() +*/ +#endif + +/*! + \fn qreal QTextOption::tabStopDistance() const + \since 5.10 + + Returns the distance in device units between tab stops. + + \sa setTabStopDistance(), tabArray(), setTabs(), tabs() +*/ + +/*! + \fn void QTextOption::setTabStopDistance(qreal tabStopDistance) + \since 5.10 + + Sets the default distance in device units between tab stops to the value specified + by \a tabStopDistance. + + \sa tabStopDistance(), setTabArray(), setTabs(), tabs() */ /*! @@ -381,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). @@ -409,32 +432,25 @@ 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 tabStop(), tabs() -*/ - -/*! \since 4.4 \fn QList<QTextOption::Tab> QTextOption::tabs() const Returns a list of tab positions defined for the text layout. - \sa tabStop(), setTabs(), setTabStop() + \sa tabStopDistance(), setTabs(), setTabStop() */ diff --git a/src/gui/text/qtextoption.h b/src/gui/text/qtextoption.h index 9ef9cee9bb..8b57278633 100644 --- a/src/gui/text/qtextoption.h +++ b/src/gui/text/qtextoption.h @@ -117,8 +117,13 @@ public: inline void setFlags(Flags flags); inline Flags flags() const { return Flags(f); } - inline void setTabStop(qreal tabStop); - inline qreal tabStop() const { return tab; } +#if QT_DEPRECATED_SINCE(5, 10) + QT_DEPRECATED inline void setTabStop(qreal tabStop); + QT_DEPRECATED inline qreal tabStop() const { return tabStopDistance(); } +#endif + + inline void setTabStopDistance(qreal tabStopDistance); + inline qreal tabStopDistance() const { return tab; } void setTabArray(const QList<qreal> &tabStops); QList<qreal> tabArray() const; @@ -149,7 +154,12 @@ inline void QTextOption::setAlignment(Qt::Alignment aalignment) inline void QTextOption::setFlags(Flags aflags) { f = aflags; } +#if QT_DEPRECATED_SINCE(5, 10) inline void QTextOption::setTabStop(qreal atabStop) +{ setTabStopDistance(atabStop); } +#endif + +inline void QTextOption::setTabStopDistance(qreal atabStop) { tab = atabStop; } QT_END_NAMESPACE 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; |