diff options
Diffstat (limited to 'src/gui/text/qfontengine_p.h')
-rw-r--r-- | src/gui/text/qfontengine_p.h | 127 |
1 files changed, 52 insertions, 75 deletions
diff --git a/src/gui/text/qfontengine_p.h b/src/gui/text/qfontengine_p.h index a81e877677..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,7 +76,8 @@ public: enum ShaperFlag { DesignMetrics = 0x0002, - GlyphIndicesOnly = 0x0004 + GlyphIndicesOnly = 0x0004, + FullStringFallback = 0x008 }; Q_DECLARE_FLAGS(ShaperFlags, ShaperFlag) @@ -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,22 +180,22 @@ 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); @@ -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 { @@ -359,14 +335,12 @@ public: 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 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; @@ -393,8 +367,6 @@ private: mutable QHash<const void *, GlyphCaches> m_glyphCaches; private: - QVariant m_userData; - mutable qreal m_minLeftBearing; mutable qreal m_minRightBearing; }; @@ -404,13 +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 size_t qHash(const QFontEngine::FaceId &f, size_t seed = 0) noexcept(noexcept(qHash(f.filename))) { - return qHashMulti(seed, f.filename, f.uuid, f.index, f.encoding); + return qHashMulti(seed, f.filename, f.uuid, f.index, f.instanceIndex, f.encoding, f.variableAxes.keys(), f.variableAxes.values()); } @@ -425,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); @@ -463,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; @@ -480,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; |