1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of the QtGui module of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:LGPL$ 9 ** Commercial License Usage 10 ** Licensees holding valid commercial Qt licenses may use this file in 11 ** accordance with the commercial license agreement provided with the 12 ** Software or, alternatively, in accordance with the terms contained in 13 ** a written agreement between you and The Qt Company. For licensing terms 14 ** and conditions see https://www.qt.io/terms-conditions. For further 15 ** information use the contact form at https://www.qt.io/contact-us. 16 ** 17 ** GNU Lesser General Public License Usage 18 ** Alternatively, this file may be used under the terms of the GNU Lesser 19 ** General Public License version 3 as published by the Free Software 20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the 21 ** packaging of this file. Please review the following information to 22 ** ensure the GNU Lesser General Public License version 3 requirements 23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. 24 ** 25 ** GNU General Public License Usage 26 ** Alternatively, this file may be used under the terms of the GNU 27 ** General Public License version 2.0 or (at your option) the GNU General 28 ** Public license version 3 or any later version approved by the KDE Free 29 ** Qt Foundation. The licenses are as published by the Free Software 30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 31 ** included in the packaging of this file. Please review the following 32 ** information to ensure the GNU General Public License requirements will 33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and 34 ** https://www.gnu.org/licenses/gpl-3.0.html. 35 ** 36 ** $QT_END_LICENSE$ 37 ** 38 ****************************************************************************/ 39 40 #ifndef QSTATICTEXT_P_H 41 #define QSTATICTEXT_P_H 42 43 // 44 // W A R N I N G 45 // ------------- 46 // 47 // This file is not part of the Qt API. It exists for the convenience 48 // of internal files. This header file may change from version to version 49 // without notice, or even be removed. 50 // 51 // We mean it. 52 // 53 54 #include <QtGui/private/qtguiglobal_p.h> 55 #include "qstatictext.h" 56 57 #include <private/qtextureglyphcache_p.h> 58 #include <QtGui/qcolor.h> 59 60 QT_BEGIN_NAMESPACE 61 62 // ### Qt 6: Unexport again, if QOpenGLStaticTextUserData (the one from QtOpenGL) is gone by then 63 class Q_GUI_EXPORT QStaticTextUserData 64 { 65 public: 66 enum Type { 67 NoUserData, 68 OpenGLUserData 69 }; 70 QStaticTextUserData(Type t)71 QStaticTextUserData(Type t) : ref(0), type(t) {} 72 virtual ~QStaticTextUserData(); 73 74 QAtomicInt ref; 75 Type type; 76 }; 77 78 class Q_GUI_EXPORT QStaticTextItem 79 { 80 public: QStaticTextItem()81 QStaticTextItem() : useBackendOptimizations(false), 82 userDataNeedsUpdate(0), usesRawFont(0), 83 m_fontEngine(nullptr), m_userData(nullptr) {} 84 setUserData(QStaticTextUserData * newUserData)85 void setUserData(QStaticTextUserData *newUserData) 86 { 87 m_userData = newUserData; 88 } userData()89 QStaticTextUserData *userData() const { return m_userData.data(); } 90 setFontEngine(QFontEngine * fe)91 void setFontEngine(QFontEngine *fe) 92 { 93 m_fontEngine = fe; 94 } 95 fontEngine()96 QFontEngine *fontEngine() const { return m_fontEngine.data(); } 97 98 union { 99 QFixedPoint *glyphPositions; // 8 bytes per glyph 100 int positionOffset; 101 }; 102 union { 103 glyph_t *glyphs; // 4 bytes per glyph 104 int glyphOffset; 105 }; 106 // ================= 107 // 12 bytes per glyph 108 109 // 8 bytes for pointers 110 int numGlyphs; // 4 bytes per item 111 QFont font; // 8 bytes per item 112 QColor color; // 10 bytes per item 113 char useBackendOptimizations : 1; // 1 byte per item 114 char userDataNeedsUpdate : 1; // 115 char usesRawFont : 1; // 116 117 private: // private to avoid abuse 118 QExplicitlySharedDataPointer<QFontEngine> m_fontEngine; // 4 bytes per item 119 QExplicitlySharedDataPointer<QStaticTextUserData> m_userData; // 8 bytes per item 120 // ================ 121 // 43 bytes per item 122 }; 123 Q_DECLARE_TYPEINFO(QStaticTextItem, Q_MOVABLE_TYPE); 124 125 class QStaticText; 126 class Q_AUTOTEST_EXPORT QStaticTextPrivate 127 { 128 public: 129 QStaticTextPrivate(); 130 QStaticTextPrivate(const QStaticTextPrivate &other); 131 ~QStaticTextPrivate(); 132 133 void init(); 134 void paintText(const QPointF &pos, QPainter *p, const QColor &pen); 135 invalidate()136 void invalidate() 137 { 138 needsRelayout = true; 139 } 140 141 QAtomicInt ref; // 4 bytes per text 142 143 QString text; // 4 bytes per text 144 QFont font; // 8 bytes per text 145 qreal textWidth; // 8 bytes per text 146 QSizeF actualSize; // 16 bytes per text 147 QPointF position; // 16 bytes per text 148 149 QTransform matrix; // 80 bytes per text 150 QStaticTextItem *items; // 4 bytes per text 151 int itemCount; // 4 bytes per text 152 153 glyph_t *glyphPool; // 4 bytes per text 154 QFixedPoint *positionPool; // 4 bytes per text 155 156 QTextOption textOption; // 28 bytes per text 157 158 unsigned char needsRelayout : 1; // 1 byte per text 159 unsigned char useBackendOptimizations : 1; 160 unsigned char textFormat : 2; 161 unsigned char untransformedCoordinates : 1; 162 // ================ 163 // 191 bytes per text 164 165 static QStaticTextPrivate *get(const QStaticText *q); 166 }; 167 168 QT_END_NAMESPACE 169 170 #endif // QSTATICTEXT_P_H 171