diff options
Diffstat (limited to 'src/gui/text/qfontengine_p.h')
-rw-r--r-- | src/gui/text/qfontengine_p.h | 162 |
1 files changed, 71 insertions, 91 deletions
diff --git a/src/gui/text/qfontengine_p.h b/src/gui/text/qfontengine_p.h index 03e14c737a..a0e0801354 100644 --- a/src/gui/text/qfontengine_p.h +++ b/src/gui/text/qfontengine_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QFONTENGINE_P_H #define QFONTENGINE_P_H @@ -65,13 +29,6 @@ class QFontEngineGlyphCache; struct QGlyphLayout; -#define MAKE_TAG(ch1, ch2, ch3, ch4) (\ - (((quint32)(ch1)) << 24) | \ - (((quint32)(ch2)) << 16) | \ - (((quint32)(ch3)) << 8) | \ - ((quint32)(ch4)) \ - ) - // ### this only used in getPointInOutline(), refactor it and then remove these magic numbers enum HB_Compat_Error { Err_Ok = 0x0000, @@ -119,17 +76,18 @@ public: enum ShaperFlag { DesignMetrics = 0x0002, - GlyphIndicesOnly = 0x0004 + GlyphIndicesOnly = 0x0004, + FullStringFallback = 0x008 }; Q_DECLARE_FLAGS(ShaperFlags, ShaperFlag) - /* Used with the Freetype font engine. We don't cache glyphs that are too large anyway, so we can make this struct rather small */ + /* Used with the Freetype font engine. */ struct Glyph { Glyph() = default; ~Glyph() { delete [] data; } short linearAdvance = 0; - unsigned char width = 0; - unsigned char height = 0; + unsigned short width = 0; + unsigned short height = 0; short x = 0; short y = 0; short advance = 0; @@ -163,11 +121,13 @@ public: virtual bool getSfntTableData(uint tag, uchar *buffer, uint *length) const; struct FaceId { - FaceId() : index(0), encoding(0) {} + FaceId() : index(0), instanceIndex(-1), encoding(0) {} QByteArray filename; QByteArray uuid; int index; + int instanceIndex; int encoding; + QMap<QFont::Tag, float> variableAxes; }; virtual FaceId faceId() const { return FaceId(); } enum SynthesizedFlags { @@ -176,14 +136,33 @@ public: SynthesizedStretch = 0x4 }; virtual int synthesized() const { return 0; } - virtual bool supportsSubPixelPositions() const { return false; } - virtual QFixed subPixelPositionForX(QFixed x) const; + inline bool supportsSubPixelPositions() const + { + return supportsHorizontalSubPixelPositions() || supportsVerticalSubPixelPositions(); + } + virtual bool supportsHorizontalSubPixelPositions() const { return false; } + virtual bool supportsVerticalSubPixelPositions() const { return false; } + virtual QFixedPoint subPixelPositionFor(const QFixedPoint &position) const; + QFixed subPixelPositionForX(QFixed x) const + { + return subPixelPositionFor(QFixedPoint(x, 0)).x; + } + + bool isColorFont() const { return glyphFormat == Format_ARGB; } + static bool isIgnorableChar(char32_t ucs4) + { + return ucs4 == QChar::LineSeparator + || ucs4 == QChar::LineFeed + || ucs4 == QChar::CarriageReturn + || ucs4 == QChar::ParagraphSeparator + || QChar::category(ucs4) == QChar::Other_Control; + } virtual QFixed emSquareSize() const { return ascent(); } /* returns 0 as glyph index for non existent glyphs */ virtual glyph_t glyphIndex(uint ucs4) const = 0; - virtual bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, ShaperFlags flags) const = 0; + virtual int stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, ShaperFlags flags) const = 0; virtual void recalcAdvances(QGlyphLayout *, ShaperFlags) const {} virtual void doKerning(QGlyphLayout *, ShaperFlags) const; @@ -201,30 +180,30 @@ public: */ // ### Refactor this into a smaller and more flexible API. virtual QImage alphaMapForGlyph(glyph_t); - virtual QImage alphaMapForGlyph(glyph_t glyph, QFixed subPixelPosition); + virtual QImage alphaMapForGlyph(glyph_t glyph, const QFixedPoint &subPixelPosition); virtual QImage alphaMapForGlyph(glyph_t, const QTransform &t); - virtual QImage alphaMapForGlyph(glyph_t, QFixed subPixelPosition, const QTransform &t); - virtual QImage alphaRGBMapForGlyph(glyph_t, QFixed subPixelPosition, const QTransform &t); - virtual QImage bitmapForGlyph(glyph_t, QFixed subPixelPosition, const QTransform &t, const QColor &color = QColor()); - virtual Glyph *glyphData(glyph_t glyph, QFixed subPixelPosition, GlyphFormat neededFormat, const QTransform &t); + virtual QImage alphaMapForGlyph(glyph_t, const QFixedPoint &subPixelPosition, const QTransform &t); + virtual QImage alphaRGBMapForGlyph(glyph_t, const QFixedPoint &subPixelPosition, const QTransform &t); + virtual QImage bitmapForGlyph(glyph_t, const QFixedPoint &subPixelPosition, const QTransform &t, const QColor &color = QColor()); + virtual Glyph *glyphData(glyph_t glyph, const QFixedPoint &subPixelPosition, GlyphFormat neededFormat, const QTransform &t); virtual bool hasInternalCaching() const { return false; } - virtual glyph_metrics_t alphaMapBoundingBox(glyph_t glyph, QFixed /*subPixelPosition*/, const QTransform &matrix, GlyphFormat /*format*/) + virtual glyph_metrics_t alphaMapBoundingBox(glyph_t glyph, const QFixedPoint &/*subPixelPosition*/, const QTransform &matrix, GlyphFormat /*format*/) { return boundingBox(glyph, matrix); } virtual void removeGlyphFromCache(glyph_t); - virtual glyph_metrics_t boundingBox(const QGlyphLayout &glyphs) = 0; + virtual glyph_metrics_t boundingBox(const QGlyphLayout &glyphs); virtual glyph_metrics_t boundingBox(glyph_t glyph) = 0; virtual glyph_metrics_t boundingBox(glyph_t glyph, const QTransform &matrix); glyph_metrics_t tightBoundingBox(const QGlyphLayout &glyphs); - virtual QFixed ascent() const = 0; + virtual QFixed ascent() const; virtual QFixed capHeight() const = 0; - virtual QFixed descent() const = 0; - virtual QFixed leading() const = 0; + virtual QFixed descent() const; + virtual QFixed leading() const; virtual QFixed xHeight() const; virtual QFixed averageCharWidth() const; @@ -304,14 +283,11 @@ public: explicit Holder(void *p, qt_destroy_func_t d) : ptr(p), destroy_func(d) {} ~Holder() { if (ptr && destroy_func) destroy_func(ptr); } Holder(Holder &&other) noexcept - : ptr(other.ptr), - destroy_func(other.destroy_func) + : ptr(std::exchange(other.ptr, nullptr)), + destroy_func(std::exchange(other.destroy_func, nullptr)) { - other.ptr = nullptr; - other.destroy_func = nullptr; } - Holder &operator=(Holder &&other) noexcept - { swap(other); return *this; } + QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(Holder) void swap(Holder &other) noexcept { @@ -353,22 +329,29 @@ public: return left_right < other.left_right; } }; - QVector<KernPair> kerning_pairs; + QList<KernPair> kerning_pairs; void loadKerningPairs(QFixed scalingFactor); GlyphFormat glyphFormat; int m_subPixelPositionCount; // Number of positions within a single pixel for this cache - inline QVariant userData() const { return m_userData; } - protected: explicit QFontEngine(Type type); - QFixed lastRightBearing(const QGlyphLayout &glyphs, bool round = false); + QFixed firstLeftBearing(const QGlyphLayout &glyphs); + QFixed lastRightBearing(const QGlyphLayout &glyphs); - inline void setUserData(const QVariant &userData) { m_userData = userData; } QFixed calculatedCapHeight() const; + mutable QFixed m_ascent; + mutable QFixed m_descent; + mutable QFixed m_leading; + mutable bool m_heightMetricsQueried; + + virtual void initializeHeightMetrics() const; + bool processHheaTable() const; + bool processOS2Table() const; + private: struct GlyphCacheEntry { GlyphCacheEntry(); @@ -384,11 +367,8 @@ private: mutable QHash<const void *, GlyphCaches> m_glyphCaches; private: - QVariant m_userData; - mutable qreal m_minLeftBearing; mutable qreal m_minRightBearing; - }; Q_DECLARE_TYPEINFO(QFontEngine::KernPair, Q_PRIMITIVE_TYPE); @@ -396,18 +376,18 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(QFontEngine::ShaperFlags) inline bool operator ==(const QFontEngine::FaceId &f1, const QFontEngine::FaceId &f2) { - return f1.index == f2.index && f1.encoding == f2.encoding && f1.filename == f2.filename && f1.uuid == f2.uuid; + return f1.index == f2.index + && f1.encoding == f2.encoding + && f1.filename == f2.filename + && f1.uuid == f2.uuid + && f1.instanceIndex == f2.instanceIndex + && f1.variableAxes == f2.variableAxes; } -inline uint qHash(const QFontEngine::FaceId &f, uint seed = 0) +inline size_t qHash(const QFontEngine::FaceId &f, size_t seed = 0) noexcept(noexcept(qHash(f.filename))) { - QtPrivate::QHashCombine hash; - seed = hash(seed, f.filename); - seed = hash(seed, f.uuid); - seed = hash(seed, f.index); - seed = hash(seed, f.encoding); - return seed; + return qHashMulti(seed, f.filename, f.uuid, f.index, f.instanceIndex, f.encoding, f.variableAxes.keys(), f.variableAxes.values()); } @@ -422,7 +402,7 @@ public: ~QFontEngineBox(); 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 int 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); @@ -460,7 +440,7 @@ public: ~QFontEngineMulti(); 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 int 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; @@ -477,10 +457,10 @@ public: 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 glyph, const QFixedPoint &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 QImage alphaMapForGlyph(glyph_t, const QFixedPoint &subPixelPosition, const QTransform &t) override; + virtual QImage alphaRGBMapForGlyph(glyph_t, const QFixedPoint &subPixelPosition, const QTransform &t) override; virtual QFixed lineThickness() const override; virtual QFixed underlinePosition() const override; @@ -510,7 +490,7 @@ protected: virtual QFontEngine *loadEngine(int at); private: - QVector<QFontEngine *> m_engines; + QList<QFontEngine *> m_engines; QStringList m_fallbackFamilies; const int m_script; bool m_fallbackFamiliesQueried; |